search
HomeBackend DevelopmentPHP TutorialDetailed explanation of the four methods of parameter transfer between PHP pages, detailed explanation of the four methods_PHP tutorial

Detailed explanation of the four methods of parameter transfer between PHP pages, detailed explanation of the four methods

      2016-04-16

Define two php files, page01.php and page02.php, and find a way to transfer the content in page01 to page02, so that we can continue to use it.
------------------------------------------------- ----------------------------------
First type:
Uses client browser cookies. 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.

The code is as follows:

<?<span>php 
       </span><span>setcookie</span>('mycookie','自灵'<span>);
</span>?>

It’s that simple, we have created the cookie.
We defined a variable mycookie, whose value is the string 'self'.
We can name the cookie variable whatever we want and define multiple cookie variables.
Accept cookies on page02.

The code is as follows:

<?<span>php
     </span><span>$wuziling</span> = <span>$_COOKIE</span>['mycookie'<span>];
     </span><span>echo</span> <span>$wuziling</span><span>;
</span>?>

We use $_COOKIE[] to extract the variable mycookie in the cookie and pay its value to $wuziling. Then simply output.
Okay, here we use cookies to transfer 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.

The code is as follows:

<?<span>php 
</span><span>session_start</span><span>();
</span><span>$_SESSION</span>["temp"]=<span>array</span>('123','456','789'<span>);
</span>?>

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.

The code is as follows:

<?<span>php 
     </span><span>session_start</span><span>();
     </span><span>for</span>(<span>$i</span>=0;<span>$i</span><3;<span>$i</span>++<span>)
     {
             </span><span>echo</span> <span>$_SESSION</span>['temp'][<span>$i</span>].'<br />'<span>;
     }
</span>?>

First start a 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.
[Don’t think that $_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 complicated, the bottom of the array The mark 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 method:
Use a form to pass.
page01.php is written like this:

The code is as follows:

<form action="page02.php" method="post">
     <input type="text" name="wuziling" />
     <input type="submit" name="submit" value="提交" />
</form>

The action attribute in the form directly specifies which page the form content 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:

The code is as follows:

<?<span>php 
     </span><span>$wu</span> = <span>$_POST</span>['wuziling'<span>];
     </span><span>echo</span> <span>$wu</span><span>;
</span>?>

Use $_POST[] to get the passed variable value. This variable name wuziling 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'];
[The value of method can also be get]
-------------------------- -------------------------------------------------- ---
The fourth method:
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:

The code is as follows:

<?<span>php 
</span><span>$var</span> = 'I love you !'<span>;
</span>?>
<a href="<?php echo "page02.php?<span>new</span>=".<span>$var</span> ?>">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:

The code is as follows:

<?<span>php
     </span><span>echo</span>   <span>$_GET</span>['new'<span>];
</span>?>

Use $_GET[ ] to get the value of new , and then you can output or use it for other purposes.
At this time, the new variable and its value can be directly seen in the browser address bar.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1121222.htmlTechArticleDetailed explanation of the four methods of parameter transfer between PHP pages, detailed explanation of the four methods 2016-04-16 Definition page01.php and page02.php two php files, find a way to transfer the content in page01 to page02, and then provide...
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
两个iphone怎么传输所有数据 详细讲解:迁移旧手机数据 的方法两个iphone怎么传输所有数据 详细讲解:迁移旧手机数据 的方法Mar 18, 2024 pm 06:31 PM

很多朋友朋友在更换苹果手机时,想把旧手机内的所有数据全部导入到新手机里,理论上是完全可行的,但在实际操作中是无法做到“转移所有”数据的,本期文章列举几种“转移部分数据”的方法。一、iTunesiTunes是苹果手机预装的软件,可用于迁移旧手机中的所有数据,但需要与电脑配合使用。可通过在电脑上安装iTunes,然后通过数据线连接手机和电脑,使用iTunes进行备份手机内的应用和数据,最后将备份恢复到新的苹果手机上来完成迁移。二、iCloudiCloud是苹果专属的“云空间”工具,可以先在旧手机内登

React API调用指南:如何与后端API进行交互和数据传输React API调用指南:如何与后端API进行交互和数据传输Sep 26, 2023 am 10:19 AM

ReactAPI调用指南:如何与后端API进行交互和数据传输概述:在现代的Web开发中,与后端API进行交互和数据传输是一个常见的需求。React作为一个流行的前端框架,提供了一些强大的工具和功能来简化这一过程。本文将介绍如何使用React来调用后端API,包括基本的GET和POST请求,并提供具体的代码示例。安装所需的依赖:首先,确保在项目中安装了Axi

Java API 开发中使用 Https 进行数据传输Java API 开发中使用 Https 进行数据传输Jun 18, 2023 pm 10:43 PM

随着科技的发展,网络通信已经成为了现代社会信息传输的重要工具之一。但同时,网络上的信息传输面临着被恶意攻击和窃取的风险,因此安全性显得尤为重要。基于此,HTTPS协议就应运而生。它是在HTTP协议上加入SSL/TLS加密的方式来保证网络传输安全性的一种协议。Java作为一门广泛应用于网络开发的语言,自然也提供了丰富的API来支持HTTPS协议。本文将

PHP trait DTO:优化数据传输过程的关键工具PHP trait DTO:优化数据传输过程的关键工具Oct 12, 2023 pm 02:33 PM

PHPtraitDTO:优化数据传输过程的关键工具,需要具体代码示例概述:在PHP开发中,数据传输是一项非常常见的任务,例如将数据从控制器传递给视图、将数据从接口传递给前端等。然而,在传输数据的过程中,往往需要对数据进行处理、转换和封装,这可能会导致代码冗余和不易维护。为了解决这个问题,我们可以使用PHPtraitDTO(DataTransfer

PHP trait DTO:优化数据传输过程的关键利器PHP trait DTO:优化数据传输过程的关键利器Oct 12, 2023 pm 03:10 PM

PHPtraitDTO:优化数据传输过程的关键利器,需要具体代码示例简介:在开发过程中,数据传输是一个非常常见的需求,尤其是在不同层级之间传递数据时。在传输这些数据过程中,我们常常需要对数据进行处理、验证或者转换,以满足不同的业务需求。为了提高代码的可读性和可维护性,我们可以使用PHPtraitDTO(DataTransferObject)来优化

PHP中如何调用API接口以实现数据的传输和处理?PHP中如何调用API接口以实现数据的传输和处理?Sep 06, 2023 am 08:21 AM

PHP中如何调用API接口以实现数据的传输和处理?随着互联网的发展,各种Web服务和API接口的使用越来越普遍。API(应用程序编程接口)是一种允许不同应用程序之间进行数据交互的技术规范。PHP作为一种广泛应用于Web开发的脚本语言,具备强大灵活的API调用能力。本文将介绍如何使用PHP语言调用API接口以实现数据的传输和处理。一、准备工作在开始调用API之

C++在嵌入式系统开发中的外围设备控制与数据传输功能实践C++在嵌入式系统开发中的外围设备控制与数据传输功能实践Aug 25, 2023 pm 07:10 PM

C++在嵌入式系统开发中的外围设备控制与数据传输功能实践引言:嵌入式系统作为一个应用领域广泛的技术,它广泛应用于许多领域,如汽车、家电、医疗设备等。在嵌入式系统开发中,外围设备控制和数据传输是一个非常重要的功能。本文将介绍如何使用C++语言实现外围设备的控制和数据传输功能,并提供实际的代码示例。一、C++外围设备控制功能实践在嵌入式系统中,外围设备控制是指通

PHP通信:如何处理数据传输中断?PHP通信:如何处理数据传输中断?Aug 19, 2023 pm 10:33 PM

PHP通信:如何处理数据传输中断?Introduction在进行数据传输的过程中,由于网络不稳定或其他原因,数据传输可能会中断。对于开发人员来说,如何处理数据传输中断是一个非常重要的问题。本文将介绍如何在PHP中处理数据传输中断的方法,并提供相关的代码示例。处理数据传输中断的方法设置超时时间在进行数据传输时,可以设置一个适当的超时时间,如果在超时时间内未完成

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment