In project development, you often see that you pass values between different pages. In web work, this article lists three common ways for you.
1. POST value transmission
Post value transfer is a method used for html's <form> form jump, which is very convenient to use. For example:
<html><form action='' method=''><input type='text' name='name1'><input type='hidden' name='name2' value='value'><input type='submit' value='submit'></form></html>
The action in form fills in the url path of the jump page, and the method fills in the post method. After pressing the submit button in the form form, the content with name in the form will be passed to the filled-in URL, which can be obtained through $_POST['name'], for example:
<?php$a=$_POST['name1'];$b=$_POST['name2'];?>
Here is a very convenient trick. When the type is selected as 'hidden' in the input tag, the input tag will be hidden and not displayed on the page. However, the input tag is in the form and has a name value and a value value. It will also be passed along with the submit button. This hidden tag can pass some content that you don't want to display.
2.GET value transmission
The GET value is passed by following the url, and when the page jumps, it jumps with the url. Commonly used in the use of <a> tags. For example:
<a href='delete.php?id=value'>Click me to jump</a>
After jumping into xxx.php, you can get the passed value through $_GET['id']. The GET method is often used for URLs to delete or read php files with a certain id.
3.SESSION value transmission
SESSION is a type of global variable, which is often used to save common data such as user ID after logging in. Once saved to SESSION, other pages can be obtained through SESSION. The session must be enabled for SESSION:
<?php//session assignment session_start(); $_SESSION['one']=value1; $_SESSION['two']=value2;//session value read: $one = $_SESSION['one']; //session value destruction unset($_SESSION['one']);?>
Thank you for reading, I hope it can help you. Thank you for your support for this site!