PHP is a server scripting language, he is now the most popular web development language, let's talk about several of the four commonly used in PHP development application of the transfer of parameters between the several methods.
The first type:
Use a cookie from the client browser. Cookie is easy to understand, is a temporary file, you can think of it as a storage room, the browser in the process of browsing to record some information, it is temporarily stored here.
Set a cookie in the page01.
The code is as follows |
Copy Code |
Setcookie ("Visittimes", $VisitTimes, Time () +31536000); ?>
|
It is so simple that we have created a cookie complete.
We define a variable MyCookie, whose value is the string ' self-spirit '.
We can name the cookie variable arbitrarily, and we can define multiple cookie variables.
Accept cookies on the Page02 page.
The code is as follows |
Copy Code |
$HTTP _cookie_vars["Visittimes"]? ($VisitTimes + +):($VisitTimes = 1);
echo " welcome you First". $VisitTimes. "Coming to my homepage n "; ?>
|
For more detailed information, please see: http://www.bKjia.c0m/phper/php-gj/33355.htm
We use $_cookie[] to extract the variable MyCookie in the COOKIE and pay its value to $wuziling. Then the simple output.
Okay, here we go. Use a cookie to pass parameters between pages.
The second type:
Use the server-side session. It's easy to understand the session. Unlike a cookie, it is a temporary storage room on the server side. The session is often referred to as a conversation.
Set a session in the PAGE01.
The code is as follows |
Copy Code |
Session_Start (); $_session["Temp"]=array (' 123 ', ' 456 ', ' 789 '); ?>
|
To use the session, you must start the session. Session_Start (); Is the way to start the session. Usually written in the front.
The second statement I defined a $_session["temp"] array whose name is $_session["Temp", which stores 3 strings.
Accept the session on the PAGE02 page.
The code is as follows |
Copy Code |
Session_Start (); for ($i =0; $i <3; $i + +) { echo $_session[' temp ' [$i]. ' '; } ?>
|
Start the session first. The variables we defined in the PAGE01 are already ready to use, and do not require any other acquired actions, unlike cookies.
Below we use a for loop to output its contents.
"Do not think $_session[' temp ' [$i] is a two-dimensional array, it is a one-dimensional array, the name of the array is $_session[" temp "], although this name is more cumbersome, the subscript of the array is ' temp '"
"When we write $_session[" temp ", temp plus double quotes or single quotes is equivalent. 】
"Here we define the session variable as an array, or we can define a normal variable, as the cookie says."
The third type:
Use the form to pass.
_post it can only receive data when PHP can only get the method= "post" of the form, as in the following code
The code is as follows |
Copy Code |
a.php page if ($_post) { echo $_post[' cn ']; } Else { Echo ' did not get the value '; } ?> |
The fourth type:
Use hyperlinks to pass parameters. Many of the things we do on the Internet are click-through hyperlinks to jump between pages. Points can also be passed as parameters.
Page01.php writes like this:
The code is as follows |
Copy Code |
$var = ' I love you! '; ?> ">get
|
Defines a variable $var.
The href attribute of hyperlink A is indicated to jump to the PAGE02 page. Add a question mark, a self-defined variable new "this name is to be used on the PAGE02 page", and the new value is the $var we want to pass.
Page02.php writes like this:
The code is as follows |
Copy Code |
echo $_get[' new ']; ?>
|
Use $_get[] to get the value of new and then output or do something else.
Note:The HTTP GET method is not suitable for large variable values, and the value cannot exceed 100 characters.
$_request variable
PHP's $_request variable contains the contents of $_get, $_post, and $_cookie.
PHP's $_request variable can be used to obtain the results of form data sent through the Get and post methods.
Example
Welcome .
You are years old!
Summarize:
We described the page transfer parameters four, Session,cookie,post,get these four methods, probably the other programming language is so much, Post,get is basically used in the form and URL to pass the parameter, page cookie, The session is stored in a global file or variable.
http://www.bkjia.com/PHPjc/629140.html www.bkjia.com true http://www.bkjia.com/PHPjc/629140.html techarticle PHP is a server scripting language, he is now the most popular web development language, let's talk about several of the four commonly used in PHP development application between the transfer of parameters ...