$ _ GET, $ _ POST, $ _ REQUEST usage and Difference Analysis in php

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.