Four ways of transferring parameters between PHP pages

time:13-06-20 forum:PHP tools and code
  Reloaded from

we define two PHP files of page01.php and page02.php, passing the contents of page01 to page02, and then for us to continue using.



First:
cookie using client browser. Cookie is easy to understand. It is a temporary file that can be regarded as a storage room. The browser records some information in the process of browsing, and it is stored here temporarily.
set a cookie in page01.
[code].lt; php
setcookie ('mycookie',' self Ling ');
.Gt; [/code]
is so simple that we have created cookie finished.
we have defined a variable mycookie, whose value is a string 'self being'.
we can name the cookie variable arbitrarily, and we can define more than one cookie variable.

accept cookie on the page02 page.
[code].lt;? Php
$wuziling = $_COOKIE.#91;'mycookie'.#93;
echo $wuziling;
?.gt; [/code]
we use the variable to extract the value of the variable. And then the simple output.
OK, here we use cookie to pass parameters between pages.

Second:
use server-side session. Understanding session is a very easy thing. Unlike cookie, it is a temporary storage room on the server side. Session is often called a conversation.
set a session in page01.
[code].lt;? Php
session_start ();
$_SESSION.#91;.Quot; temp.quot;.#93; =array ('123','456',); Session_start (); is the way to start session. It is generally written in the front.
second statements I define a $_SESSION[.quot; temp.quot;] array, the name of the array is $_SESSION[.quot; temp.quot;], which stores 3 strings.
accept session on the page02 page.
[code].lt;? Php
session_start ();
for ($i=0; $i.lt; $i)
{
echo; After we start, the variables defined in page01 can be used without any other operations. This is different from cookie.
below we use the for loop to output its contents.
[do not think that $_SESSION['temp'][$i] is a two-dimensional array, it is a one-dimensional array, the name of the array is $_SESSION[.quot; temp.quot;], although the name is more tedious, the subscript of the array is'temp'
[we are writing $_SESSION[.quot; temp.quot;], temp plus double quotes or single quotes are all equivalent .
[where we define session variables here, we define an array, and you can define a common variable, as in cookie)





Third:
use form to pass.
[code]page01.php writes such as:
.lt; form action=.quot; page02.php.quot; method=.quot; post.quot;.Gt;
.Lt. /code]
property in the form action directly specifies which page the content of this form is passed to. Method indicates the way of delivery. Post represents the use of message passing, just like we send text messages.
page02.php writes such as:
[code].lt;? Php
$wu = $_POST.#91;'wuziling'.#93;
echo $wu;
> > to get the passed variable values. The variable name wuziling is defined in the name attribute of the input label of the form.
and then pass it to another variable $wu. So we can output it. Direct output is also possible, echo $_POST['wuziling'];
[if where not understood, please refer to another detailed description of the form submitted by this block]
[method value can also be get]

Fourth:
use hyperlinks to transfer parameters. Many of the operations we use on the Internet are clicking hyperlinks to jump between pages. It can also transfer parameters at the same time.
page01.php writes such as:
[code].lt; php
$var ='I love you! The href attribute of
hyperlink a indicates that you want to jump to page02 page. A question mark is added later, a variable new that is defined by itself [this name is used in page02 pages], and the value of new is the $var we want to pass.
page02.php writes such as:
[code].lt;? Php
echo $_GET.#91;'new'.#93;
?.gt; [/code]
use $_GET[] to get the values, and then you can output or do other uses.
browser address bar at this time can directly see the new variable and its value.

prev:Mengniu yogurt drinks green floc, the ma... next:Processing techniques for PHP passing th...
post comment
Notice



approved   [craftsman road] a legendary brother...   May 1 go to these scenic spots to pl...   Do not work to go to school and not ...   Tea table "dark words"   Bazhong man built a small wooden bri...
rand   A practical MySQL Ajax PHP cascade t...   Analyze the process and principle of...   The setcookie function of PHP   PHP functions to solve the URL encod...   The encoding (Unicode) at the beginn...
ads

other

Because all the contents of this site are reproduced from other media, the intention is to provide free services to the public, but it does not mean that this site agrees with its views, and can not be responsible for the authenticity of its verification, such as the copyright unit or individual of the manuscript does not want to publish on this site, please Contact me, I will immediately remove it, thank you. Contact: atseashawk@163.com