Home  >  Article  >  Backend Development  >  How to pass values ​​between different pages in php

How to pass values ​​between different pages in php

王林
王林Original
2020-09-19 16:23:332564browse

How PHP transfers values ​​between different pages: 1. Use post to transfer values; 2. Use get to transfer values; 3. Use session to transfer values. Session is a type of global variable. It is often used to save common data such as user ID after the user logs in. Choosing session is a very good choice.

How to pass values ​​between different pages in php

Three commonly used methods:

1. POST value transmission

(Recommended tutorial: php video Tutorial)

Post value is a method used for HTMLff9c23ada1bcecdd1a0fb5d5a0f18437 form jump, which is very convenient to use. For example:

 
 

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:

here A very convenient tip. When selecting type as 'hidden' in the input tag, the input tag will be hidden and will not be displayed on the page. However, if the input tag is in the form and has a name value and a value value, it will also follow The submit button is passed, and this hidden label can pass some content that you don't want to display.

2. GET value transfer

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

点我跳转

After jumping to 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: php training

The above is the detailed content of How to pass values ​​between different pages in php. 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