The advantages and disadvantages of $ _ GET, $ _ POST, and $ _ REQUEST are described as examples. For more information, see.
1. $ _ REQUEST
The $ _ GET, $ _ POST, and $ _ COOKIE arrays are included by default.
| The Code is as follows: |
Copy code |
<? Php $ _ GET ['foo'] = 'a '; $ _ POST ['bar'] = 'B '; Var_dump ($ _ GET); // Element 'foo' is string (1) "" Var_dump ($ _ POST); // Element 'bar' is string (1) "B" Var_dump ($ _ REQUEST); // Does not contain elements 'foo' or 'bar' ?> |
Note: It is slower than others.
2. $ _ GET
The $ _ GET variable is used to collect the values in the form from method = "get. The information sent from a form with the GET method is visible to anyone (displayed in the address bar of the browser), and the amount of information sent is limited (up to 100 characters ).
Instance
| The Code is as follows: |
Copy code |
Welcome. php? Name = Peter & age = 37 |
The welcome. php file can now GET form data using the $ _ GET variable (note that the name of the form field will automatically become the ID key in the $ _ GET array ):
| The Code is as follows: |
Copy code |
Welcome <? Php echo $ _ GET ["name"];?>. <Br/> You are <? Php echo $ _ GET ["age"];?> Years old! |
Note: The data size cannot exceed 100 characters or 2 kb at most.
3. $ _ POST
The $ _ POST variable is an array with the variable name and value sent by the http post method.
The $ _ POST variable is used to collect the values in the form from method = "post. The information sent from a form with the POST method is invisible to anyone (not displayed in the address bar of the browser) and there is no limit on the amount of information sent.
| The Code is as follows: |
Copy code |
<Form action = "welcome. php" method = "post"> Enter your name: <input type = "text" name = "name"/> Enter your age: <input type = "text" name = "age"/> <Input type = "submit"/> </Form> |
Selcome. php file
| The Code is as follows: |
Copy code |
Welcome <? Php echo $ _ POST ["name"];?>. <Br/> You are <? Php echo $ _ POST ["age"];?> Years old! |
Note: It is much better than get to process a large amount of data while mostly used for forms.
The three difference is that $ _ REQUEST can GET the data of $ _ GET and $ _ post, but the efficiency is slower than the previous two. Why is it slow, let's leave your thoughts here.