Detailed explanation of 4 PHP page parameter passing examples
We define two php files, page01.php and page02.php, and find a way to transfer the content in page01 to page02, and then continue to use it.
---------------------------------------- ---------------------------------------
First Type:
Use the client browser's cookie. A cookie is easy to understand. It is a temporary file. You can think of it as a storage room. The browser records some information during the browsing process and temporarily stores it here.
Set a cookie in page01.
<?php setcookie('mycookie','自灵'); ?>
It’s that simple, we have created the cookie.
We defined a variable mycookie, its value is string 'self-spirit'.
We can name the cookie variable whatever we want and define multiple cookie variables.
Accept cookies on page02.
<?php $wuziling = $_COOKIE['mycookie']; echo $wuziling; ?>
We use $_COOKIE[] to extract the variable mycookie in the cookie and pay its value to $wuziling. Then simply output.
Okay, here we are done using cookies to pass parameters from page to page.
-------------------------------------------------- ----------------------------------
Second type:
Use server-side session. Understanding session is very easy. The difference from a cookie is that it is a temporary storage on the server side. Session is often called a session.
Set a session in page01.
<?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.
<?php session_start(); for($i=0;$i<3;$i++) { echo $_SESSION['temp'][$i].'<br />'; } ?>
Start the session first. 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 for loop to output its content.
[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 this 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, just like what is mentioned in cookies】
----------------- -------------------------------------------------- -------------
Third option:
Use a form to pass.
page01.php is written like this:
<form action="page02.php" method="post"> <input type="text" name="wuziling" /> <input type="submit" name="submit" value="提交" /> </form>
The attribute action in the form directly specifies which page the content of this form is transferred to. method specifies the method of delivery. post stands for using messaging, just like how we send text messages.
page02.php is written like this:
<?php $wu = $_POST['wuziling']; echo $wu; ?>
Use $_POST[] to get the passed variable value. This variable namewuziling is defined in the name attribute of the form's input tag.
Then pass it to another variable $wu. So we can output. Direct output is also possible, echo $_POST['wuziling'];
[If you don’t understand something, please refer to another post in this section that details form submission]
[The value of method can also be get]
-------------------------------------------------- ----------------------------------
Fourth type:
Use hyperlinks to pass parameters. Many of our online operations involve clicking on hyperlinks to jump between web pages. Parameters can also be passed while clicking.
page01.php is written like this:
<?php $var = 'I love you !'; ?> <a href="<?php echo "page02.php?new=".$var ?>">get</a>
Define a variable $var.
The href attribute of hyperlink a states that it will jump to the page02 page. Add a question mark after it and a self-defined variable new [this name will be used on the page02 page]. The value of new is the $var we want to pass.
page02.php is written like this:
<?php echo $_GET['new']; ?>
Use $_GET[] to get the value of new, and then it can be output or used for other purposes.
At this time, the new variable and its value can be directly seen in the browser address bar.
The above is the detailed content of Detailed explanation of 4 PHP page parameter passing examples. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

If you are an experienced PHP developer, you might have the feeling that you’ve been there and done that already.You have developed a significant number of applications, debugged millions of lines of code, and tweaked a bunch of scripts to achieve op

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

A string is a sequence of characters, including letters, numbers, and symbols. This tutorial will learn how to calculate the number of vowels in a given string in PHP using different methods. The vowels in English are a, e, i, o, u, and they can be uppercase or lowercase. What is a vowel? Vowels are alphabetic characters that represent a specific pronunciation. There are five vowels in English, including uppercase and lowercase: a, e, i, o, u Example 1 Input: String = "Tutorialspoint" Output: 6 explain The vowels in the string "Tutorialspoint" are u, o, i, a, o, i. There are 6 yuan in total

This tutorial demonstrates how to efficiently process XML documents using PHP. XML (eXtensible Markup Language) is a versatile text-based markup language designed for both human readability and machine parsing. It's commonly used for data storage an

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

What are the magic methods of PHP? PHP's magic methods include: 1.\_\_construct, used to initialize objects; 2.\_\_destruct, used to clean up resources; 3.\_\_call, handle non-existent method calls; 4.\_\_get, implement dynamic attribute access; 5.\_\_set, implement dynamic attribute settings. These methods are automatically called in certain situations, improving code flexibility and efficiency.
