Home >Backend Development >PHP Problem >What is the difference between predefined arrays $_post and $_get in php

What is the difference between predefined arrays $_post and $_get in php

青灯夜游
青灯夜游Original
2021-10-25 18:41:542264browse

Difference: 1. "$_GET" is used to collect values ​​from the form of "method="get"", while "$_POST" is used to collect values ​​from the form of "method="post"" value; 2. The contents of "$_GET" will be displayed in the URL, but "$_POST" will not.

What is the difference between predefined arrays $_post and $_get in php

The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer

PHP predefined variables ($_GET and $_POST)

$_GET

$_GET variable is an array whose content is the variable name sent by the HTTP GET method and value.

$_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).

When using $_GET variables, all variable names and values ​​will be displayed in the URL. So this method should not be used when sending passwords or other sensitive information. However, because the variables appear in the URL, you can bookmark the page. In some cases this is useful.

At the same time, the HTTP GET method is not suitable for large variable values; the value cannot exceed 100 characters.

$_POST

$_POST variable is an array containing the variable names and values ​​sent by the HTTP POST method.

$_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.

Example:

<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>

When the user clicks the submit button, the URL will not contain any form data and looks similar to this: http://www.php.cn/welcome.php

The "welcome.php" file can now retrieve form data via the $_POST variable (note that the name of the form field automatically becomes the ID key in the $_POST array):

Welcome <?php echo $_POST["name"]; ?>.<br />
You are <?php echo $_POST["age"]; ?> years old!

Via HTTP POST The variables sent will not appear in the URL. There is no length limit for variables.

However, since the variable does not appear in the URL, the page cannot be bookmarked.

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of What is the difference between predefined arrays $_post and $_get in php. For more information, please follow other related articles on the PHP Chinese website!

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