PHP is a server scripting language, and he is now the most popular web development language, the following we describe several of the PHP development applications commonly used in the four of different ways to pass parameters between the two.
First type:
Use a cookie from the client browser. Cookies are easy to understand, is a temporary file, you can see it as a storage room, the browser in the process of browsing the record of some information, temporarily stored here.
Set a cookie in PAGE01.
<?php
Setcookie ("Visittimes", $VisitTimes, Time () +31536000);
?>
It is so simple that we have created the cookie complete.
We define a variable MyCookie, whose value is the string ' self '.
We can simply name the cookie variable, and we can define multiple cookie variables.
Accept cookies on the Page02 page.
?
$HTTP _cookie_vars["Visittimes"]? ($VisitTimes + +):($VisitTimes = 1);
Echo <b> Welcome to <font color= "#FF0000 >". $VisitTimes.
"</font> Visit my homepage </b><br>n";
?>
For more details please see: http://www.111cn.net/phper/php-gj/33355.htm
We use $_cookie[] to extract the variable MyCookie from the COOKIE and pay its value to $wuziling. And then the simple output.
All right, here we go. Use cookies to pass arguments between pages.
The second type:
Use server-side session. Understanding the session is an easy task. The difference with a cookie is that it is a temporary storeroom on the server side. Sessions are often called conversations.
Set a session in PAGE01.
<?php
Session_Start ();
$_session["Temp"]=array (' 123 ', ' 456 ', ' 789 ');
?>
To use session, you must start the session. Session_Start () is the way to start the session. Usually write at the front.
The second statement defines a $_session["temp" array whose name is $_session["Temp", which stores 3 strings.
Accept the session on the PAGE02 page.
<?php
Session_Start ();
For ($i =0 $i <3; $i + +)
{
echo $_session[' temp ' [$i]. ' <br/> ';
}
?>
Start the session first. The variables we defined in PAGE01 are already available after startup and do not require any additional operations, unlike cookies.
Below we use a for loop to output its content.
"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 array subscript is ' temp '"
"When we write $_session[" temp ", the temp plus double quotes or single quotes are equivalent. 】
"Here we define the session variable as an array, or we can define a generic variable, as the cookie says."
The third type:
Use forms to pass.
_post it can only receive data when PHP can only get the form's method= "POST", the following code
<form id= "Form1" Name= "Form1" method= "Get" action= "" >
<label>
<input type= "text" Name= "cn" value= ' Get Me '/>
</label>
</form>a.php page
?
if ($_post)
{
echo $_post[' cn '];
}
Else
{
Echo ' did not get value ';
}
?>
The fourth kind:
Pass parameters by using hyperlinks. Many of the things we do on the Internet are clicking hyperlinks to jump between the pages. Point can also pass parameters.
Page01.php writes:
<?php
$var = ' I love you! '
?>
<a href= "Http://www.111cn.net <?php echo" page02.php?new= ". $var?>" >get</a>
Define a variable var.
The href attribute of hyperlink A is stated to jump to the PAGE02 page. Add a question mark later, a variable of your own definition "this name is used on PAGE02 page", the value of new is the Var we want to pass.
Page02.php writes:
<?php
echo $_get[' new '];
?>
Use $_get[] to get the value of new, which can then be exported or used for other purposes.
Note: HTTP GET methods are not suitable for large variable values; values cannot exceed 100 characters.
$_request variable
PHP's $_request variables contain $_get, $_post, and $_cookie content.
PHP's $_request variable can be used to obtain the results of form data sent through the Get and post methods.
Example
Welcome <?php Echo $_request["name";? >.<br/>
are <?php echo $_request["age";?> Perton old!
Summary:
We described above four kinds of page passing parameters, session,cookie,post,get these four methods, probably other programming languages also so many, post,get basically used in the form and URL to pass, page cookies, The session is to save the pass in a global file or variable.