There are three common methods for passing PHP parameters: $ _ POST [], $ _ GET [], and $ _ SESSION [], which are used to obtain the values of form, URL, and Session variables respectively. There are three common methods for passing PHP parameters:
$ _ POST [], $ _ GET [], $ _ SESSION [],Obtain the values of form, URL, and Session variables respectively.
1. $ _ POST [] global variables
Use the $ _ POST [] pre-defined variable in PHP to obtain the value of the form element. Format: $ _ POST [name]
Create a form. php, set the method attribute to POST, add a text box, and name it user.
form
The attribute action in the form directly specifies the page on which the form content is transmitted. Method indicates the transfer method. Post indicates message transmission, just like sending a text message.
Then we can get the form element, the code is as follows:
Note: in some PHP versions, you can directly write $ user to call the value of the form element, which is related to the setting of php. ini. In the php. ini file, this line of code register_globals = ON/OFF is retrieved. if it is ON, it can be directly written as $ user, but not vice versa. Although it is convenient to directly apply the form name, register_globals = OFF is generally recommended for security reasons.
2. $ _ GET [] global variables
PHP uses the $ _ GET [] global variable to obtain the value of the form element obtained through the GET () method. the format is as follows: $ _ GET [name]
In this way, you can directly use the value of the form element named name.
Use hyperlinks to pass parameters. Many of our online operations involve clicking hyperlinks to jump between webpages. You can also pass parameters.
Create a form. php, set the method attribute to GET, add a text box, and name it user.
form
The attribute action in the form directly specifies the page on which the form content is transmitted. Method indicates how to use get to pass.
Then we can get the form element, the code is as follows:
Note: PHP can apply the $ _ POST [] or $ _ GET [] global variable to obtain the value of the form element. However, it is worth noting that the names of the obtained form elements differ in uppercase and lowercase letters. If you neglect the case sensitivity when writing a Web program, you cannot obtain the value of the form element or an error message is displayed during search.
3. $ _ SESSION [] variable
Use the $ _ SESSION [] variable to obtain the value of the form element. the format is $ _ SESSION [name].
For example, create a form and add a text box named "user". the code for getting the form element is as follows:
The variable value obtained using the $ _ SESSION [] parameter passing method can be used on any page after saving. However, this method consumes system resources. we recommend that you use it with caution. For the $ _ SESSION variable, refer to the application code example of PHP session on the Chinese php website.
The above is a detailed explanation of common methods for passing php parameters. For more information, see other related articles in the first PHP community!