Home  >  Article  >  Backend Development  >  Usage and difference analysis of $_GET, $_POST, $_REQUEST in PHP_PHP tutorial

Usage and difference analysis of $_GET, $_POST, $_REQUEST in PHP_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 16:59:551271browse

The article explains the advantages and disadvantages of $_GET, $_POST, $_REQUEST and the usage of the three of them with examples. Friends in need can refer to it.

1. $_REQUEST

Contains an array of $_GET, $_POST and $_COOKIE by default.

The code is as follows
 代码如下 复制代码

$_GET['foo'] = 'a';
$_POST['bar'] = 'b';
var_dump($_GET); // Element 'foo' is string(1) "a"
var_dump($_POST); // Element 'bar' is string(1) "b"
var_dump($_REQUEST); // Does not contain elements 'foo' or 'bar'

?>

Copy code

$_GET['foo'] = 'a';

$_POST['bar'] = 'b';

var_dump($_GET); // Element 'foo' is string(1) "a"

var_dump($_POST); // Element 'bar' is string(1) "b"
代码如下 复制代码

welcome.php?name=Peter&age=37

var_dump($_REQUEST); // Does not contain elements 'foo' or 'bar'

?>

 代码如下 复制代码

Welcome .

You are years old!

Note: Its speed is slower than others

2. $_GET

The $_GET variable is used to collect values ​​from the form with method="get". Information sent from a form with the GET method is visible to everyone (displayed in the browser's address bar), and there is a limit on the amount of information sent (maximum 100 characters).
 代码如下 复制代码


Enter your name:
Enter your age:

Example

The code is as follows
 代码如下 复制代码

Welcome .

You are years old!

Copy code

welcome.php?name=Peter&age=37

welcome.php" file can now retrieve form data via the $_GET variable (note that the name of the form field automatically becomes the ID key in the $_GET array):
The code is as follows Copy code
Welcome .
You are years old! Note: The amount of data cannot be too large and can only be up to 100 characters or 2kb 3. $_POST The $_POST variable is an array containing the variable names and values ​​sent by the HTTP POST method. The $_POST variable is used to collect values ​​from the form with method="post". Information sent from a form with the POST method is invisible to anyone (it does not appear in the browser's address bar), and there is no limit on the amount of information sent.
The code is as follows Copy code
Enter your name: Enter your age:
selcome.php file
The code is as follows Copy code
Welcome .
You are years old! Note: It is much better than get and has a large amount of data processing and is mostly used in forms. The third difference is that $_REQUEST can obtain the data of $_GET and $_post, but the efficiency is slower than the first two. I think everyone can figure out why it is slow, so I will leave you with your thoughts here.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/631304.htmlTechArticleThe article explains the advantages and disadvantages of $_GET, $_POST, $_REQUEST and the usage of the three of them. Illustrate it with examples, friends in need can refer to it. 1. $_REQUEST includes by default...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn