Home>Article>Backend Development> How to pass the value of a variable between pages in php
Value transfer between different pages is often used in web work. This article lists 3 common and practical methods
I have been exposed to PHP for several months. This article summarizes the three different page value transfer methods commonly used in the programming process during this period. I hope it can be a reference for everyone. If you have any opinions, I hope you can discuss them together.
1. POST value transfer(Recommended learning:PHP programming from entry to proficiency)
Post value transfer is used for html The ff9c23ada1bcecdd1a0fb5d5a0f18437 form jump method 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 is 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 passing value
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. The use of SESSION must be turned on
Regarding the pros and cons of the three methods, the get value is displayed in the URL link, which is very unsafe. If you want To link to another page, post is not very convenient to use. Selecting session is a good and convenient method.
The above is the detailed content of How to pass the value of a variable between pages in php. For more information, please follow other related articles on the PHP Chinese website!