PHP $ _ GET and $ _ POST variables are used to obtain information in the form, such as user input information.
PHP4.1 (like) cancels the direct receipt of variables, and uses $ _ GET ['variable name'] to receive the variables passed from the link, use $ _ POST ['variable name'] to receive the variables submitted from the form. There are also $ _ FILES [], $ _ SERVER [], etc.
The following is an HTML file. This HTML contains an HTML Form, which is mainly used for users to enter their names.
The code is as follows: |
Copy code |
<Form action = "get. php" method = "get"> Name: <Input type = "text" name = "username"/> <Input type = "submit" value = "OK"/> </Form> |
The HTML display interface is as follows:
When you enter a name in the form text box of this HTML file, such as "Jacky", and then click the OK button, it will jump to get. php, which will be displayed in get. php, as shown in the figure below.
The source code of get. php is as follows:
The code is as follows: |
Copy code |
<? Php echo $ _ GET ["username"]?>. |
Obtain the data of the form control by taking the name value of the form control.
For example, "username" is the name value of the text input box of the form control,
The code is as follows: |
Copy code |
<Input type = "text" name = "username"/> |
You can use $ _ GET ["username"] to obtain the data in the text input box.
The code is as follows: |
Copy code |
<? Php echo $ _ GET ["username"]?>
|
Obtain HTML Form (HTML Form) single dataset (input type = "radio") data
You can obtain the value of the single-sheet signature by taking the name value of the single-sheet signature.
$ _ POST: get HTML form submission data
The following is an HTML file. This HTML contains an HTML Form, which is mainly used for users to input user names.
The code is as follows: |
Copy code |
<Form action = "post. php" method = "post"> Name: <input type = "text" name = "username"/> <Input type = "submit" value = "OK"/> </Form>
|
When You enter a name in the text box of the HTML Form, such as "Jacky", and then click OK, the page will jump to post. php. The output result is You are Jacky .. The source code of post. php is as follows:
The code is as follows: |
Copy code |
You are <? Php echo $ _ POST ["username"]?>.
|
Obtain the data of the form control by taking the name value of the form control.
For example, "username" is the name value of the text input box of the form control,
The code is as follows: |
Copy code |
<Input type = "text" name = "username"/> |
You can use $ _ POST ["username"] to obtain the data in the text input box.
The code is as follows: |
Copy code |
<? Php echo $ _ POST ["username"]?> |
$ _ REQUEST variable
The PHP $ _ REQUEST variable contains $ _ GET, $ _ POST, and $ _ COOKIE content.
The PHP $ _ REQUEST variable can be used to obtain the form data sent through the "GET" and "POST" methods.
Case
The code is as follows: |
Copy code |
Welcome <? Php echo $ _ REQUEST ["name"];?>. <Br/> You are <? Php echo $ _ REQUEST ["age"];?> Years old |