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!

PHP remains a powerful and widely used tool in modern programming, especially in the field of web development. 1) PHP is easy to use and seamlessly integrated with databases, and is the first choice for many developers. 2) It supports dynamic content generation and object-oriented programming, suitable for quickly creating and maintaining websites. 3) PHP's performance can be improved by caching and optimizing database queries, and its extensive community and rich ecosystem make it still important in today's technology stack.

In PHP, weak references are implemented through the WeakReference class and will not prevent the garbage collector from reclaiming objects. Weak references are suitable for scenarios such as caching systems and event listeners. It should be noted that it cannot guarantee the survival of objects and that garbage collection may be delayed.

The \_\_invoke method allows objects to be called like functions. 1. Define the \_\_invoke method so that the object can be called. 2. When using the $obj(...) syntax, PHP will execute the \_\_invoke method. 3. Suitable for scenarios such as logging and calculator, improving code flexibility and readability.

Fibers was introduced in PHP8.1, improving concurrent processing capabilities. 1) Fibers is a lightweight concurrency model similar to coroutines. 2) They allow developers to manually control the execution flow of tasks and are suitable for handling I/O-intensive tasks. 3) Using Fibers can write more efficient and responsive code.

The PHP community provides rich resources and support to help developers grow. 1) Resources include official documentation, tutorials, blogs and open source projects such as Laravel and Symfony. 2) Support can be obtained through StackOverflow, Reddit and Slack channels. 3) Development trends can be learned by following RFC. 4) Integration into the community can be achieved through active participation, contribution to code and learning sharing.

PHP and Python each have their own advantages, and the choice should be based on project requirements. 1.PHP is suitable for web development, with simple syntax and high execution efficiency. 2. Python is suitable for data science and machine learning, with concise syntax and rich libraries.

PHP is not dying, but constantly adapting and evolving. 1) PHP has undergone multiple version iterations since 1994 to adapt to new technology trends. 2) It is currently widely used in e-commerce, content management systems and other fields. 3) PHP8 introduces JIT compiler and other functions to improve performance and modernization. 4) Use OPcache and follow PSR-12 standards to optimize performance and code quality.

The future of PHP will be achieved by adapting to new technology trends and introducing innovative features: 1) Adapting to cloud computing, containerization and microservice architectures, supporting Docker and Kubernetes; 2) introducing JIT compilers and enumeration types to improve performance and data processing efficiency; 3) Continuously optimize performance and promote best practices.


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

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Dreamweaver CS6
Visual web development tools

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

SublimeText3 Linux new version
SublimeText3 Linux latest version