Home > Article > Backend Development > How to pass parameters when php page jumps
How to transfer parameters by php page jump: You can transfer parameters between pages by using the server-side session. Session is a temporary storage room on the server side, often called a session. To use a session, you must start the session through the session_start() statement.
# You can use the server-side session.
(Recommended tutorial: php graphic tutorial)
The difference between session and cookie is that it is a temporary storage room on the server side. Session is often called a session.
Set a session in page01.
The code is as follows:
<?php session_start(); $_SESSION["temp"]=array('123','456','789'); ?>
To use session, session must be started. session_start(); is the method to start the session. Generally it should be written first.
In the second statement, I defined a $_SESSION["temp"] array. The name of the array is $_SESSION["temp"], which stores 3 strings.
Accept session on page02.
(Video tutorial recommendation: php video tutorial)
The code is as follows:
<?php session_start(); for($i=0;$i<3;$i++) { echo $_SESSION['temp'][$i].'<br />'; } ?>
First start the session. After startup, the variables we defined in page01 are already available and do not require any other acquisition operations. This is different from cookies.
Below we use a for loop to output its content.
Note:
Don’t think that $_SESSION['temp'][$i] is a two-dimensional array, it is a one-dimensional array, and the name of the array is $_SESSION["temp"] , although the name is cumbersome, the subscript of the array is 'temp'.
When we write $_SESSION["temp"], temp plus double quotes or single quotes are equivalent.
Here we define an array when defining session variables, or we can define ordinary variables.
The above is the detailed content of How to pass parameters when php page jumps. For more information, please follow other related articles on the PHP Chinese website!