Three ways to pass values across php pages

不言
Release: 2023-03-23 07:52:02
Original
6578 people have browsed it

The content of this article is the three cross-page value transfer methods in PHP. Now I share it with everyone, and can also give a reference to friends in need

1. POST value transfer

Post value is a method used for HTML

form jump, which is very convenient to use. For example:



?

1

2

3

4

5

6

7


<html>

<form action='' method=''>

<input type='text' name='name1'>

<input type='hidden' name='name2' value='value'>

<input type='submit' value='提交'>

form>

html>


The action in the form is filled in with the url path of the jump page, and the method is filled in with the post method. After the submit button in the form is pressed, all the content with name in the form will be transferred to the filled in URL, which can be obtained through $_POST['name'], for example:



?

##1

2

3

4


##

$a=$_POST['name1'];

$b=$_POST['name2'];

?>


There is a very convenient trick here. When the type is selected as 'hidden' in the input tag, the input tag will be hidden and will not be displayed on the page, but the input tag will be displayed on the page. In the form, there are name values and value values, which will also be passed along with the submit button. This hidden tag can pass some content that you do not want to display.

2. GET value transmission

GET value transmission is passed by following the url. When the page jumps, it jumps with the url. Commonly used in the use of tags. For example:



?

1


<#a href='delete.php?id=value'> ;Click me to jumpa>


After jumping into xxx.php, you can get the passed value through $_GET['id']. The GET method is often used in URLs to delete or read a php file with a certain ID.

3. SESSION value transfer

SESSION is a type of global variable, which is often used to save common data such as user ID after the user logs in. Once saved to SESSION, other pages can be obtained through SESSION. To use SESSION, you need to open the session:



?

##


The above three methods are common methods, you can refer to them.

Regarding the pros and cons of the three methods, the value passed by get is displayed in the URL link, which is very unsafe. If you want to link to another page, post is not convenient to use. It is very good and convenient to choose session. Methods

.

Related recommendations:

Detailed explanation of the difference between passing by value and passing by reference in php


##1

2

3

4

5

6

7

8

9

10

11

12


//session赋值

session_start();

$_SESSION['one']=value1;

$_SESSION['two']=value2;

//Reading the session value:

$one = $ _SESSION['one'];

//Destruction of session value

unset($_SESSION['one']);

?>

The above is the detailed content of Three ways to pass values across php pages. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!