Home >Backend Development >PHP Problem >How to pass parameters when php page jumps

How to pass parameters when php page jumps

王林
王林Original
2020-08-01 13:51:275041browse

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.

How to pass parameters when php page jumps

# 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(&#39;123&#39;,&#39;456&#39;,&#39;789&#39;);
?>

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[&#39;temp&#39;][$i].&#39;<br />&#39;;
     }
?>

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn