PHP $_POST variable
In the above section we talked about the $_GET variable, so in this section we will learn about the $_POST variable to collect the value in the form with method="post".
$_POST variable
The predefined $_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 (will not be displayed in the browser's address bar), and there is no limit on the amount of information sent.
Note: However, by default, the maximum amount of information sent by the POST method is 8 MB (can be changed by setting post_max_size in the php.ini file).
Now let’s look at it with an example
Example
php中文网(php.cn)
Submit to php_post.php page
"; echo "你的性别是:" .$_POST['sex']."
"; echo "你的年龄是:".$_POST['age']; ?>
Program running results:
We see, The information we submitted using POST is not displayed in the Url column, so you now know that POST is more secure than GET
The difference between GET and POST:
get is to obtain data from the server, and post is to transmit data to the server.
get adds the parameter data queue to the URL pointed to by the ACTION attribute of the submitted form. The value corresponds one-to-one to each field in the form, which can be seen in the URL. . Post uses the HTTP post mechanism to place each field in the form and its content in the HTML HEADER and transmit it to the URL address pointed to by the ACTION attribute. Users cannot see this process.
For the get method, the server side uses Request.QueryString to obtain the value of the variable. For the post method, the server side uses Request.Form to obtain the submitted data.
The amount of data transferred by get is small and cannot be larger than 2KB. The amount of data transmitted by post is relatively large and is generally unrestricted by default. But in theory, the maximum amount is 80KB in IIS4 and 100KB in IIS5.
get security is very low, post security is high. But the execution efficiency is better than the Post method.
Suggestions:
1. The get method is less secure than the post method, including For confidential information, it is recommended to use the Post data submission method;
2. When doing data query, it is recommended to use the Get method; when doing data addition, modification or deletion, it is recommended to use the Post method;
PHP $_REQUEST variable
##The predefined $_REQUEST variable includes $_GET, $_POST and the contents of $_COOKIE. $_REQUEST variable can be used to collect form data sent via GET and POST methods. Modify the above php file and take a look
"; echo "你的性别是:" .$_REQUEST['sex']."
"; echo "你的年龄是:".$_REQUEST['age']; ?>
You will find that whether it is submitted by $_POST or $_GET, it can be received with $_REQUEST