PHP $_POST variable
In PHP, the predefined $_POST variable is used to collect values from the form with method="post".
$_POST variable
The predefined $_POST variable is used to collect forms from method="post" value in .
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).
Example
form.html file code is as follows:
<html> <head> <meta charset="utf-8"> <title>php中文网(php.cn)</title> </head> <body> <form action="welcome.php" method="post"> 名字: <input type="text" name="fname"> 年龄: <input type="text" name="age"> <input type="submit" value="提交"> </form> </body> </html>
When the user clicks the "Submit" button, the URL is similar to the following:
When to use method="post"?
Information sent from a form with the POST method is invisible to anyone, and there is no limit on the amount of information sent.
However, since the variable does not appear in the URL, the page cannot be bookmarked.
PHP $_REQUEST variable
The predefined $_REQUEST variable contains the contents of $_GET, $_POST and $_COOKIE.
$_REQUEST variable can be used to collect form data sent via GET and POST methods.
Example
You can modify the "welcome.php" file to the following code, which can accept $_GET, $_POST and other data.
Welcome<?php echo $_REQUEST["fname"]; ?>!<br>
Your age is<?php echo $_REQUEST["age"] ; ?> Years old.
The difference between GET and POST value transfer methods:
1. Get adds the data in the form to the form in the form of variable=value. Behind the URL pointed to by the action, and the two are connected using "?", and each variable is connected using "&"; Post puts the data in the form in the data body of the form, according to the corresponding way of variables and values. , passed to the URL pointed to by the action.
2, Get is unsafe because during the transmission process, the data is placed in the requested URL, and many existing servers, proxy servers or user agents will record the request URL in log files. , and then put it somewhere so that some private information may be seen by a third party. In addition, users can also see the submitted data directly on the browser, and some internal system messages will be displayed in front of the user. All Post operations are invisible to users.
3. The amount of data transferred by Get is small, mainly because it is limited by the URL length; while Post can transfer a large amount of data, so only Post can be used to upload files (of course there is another reason, which will be discussed later) mentioned).
4, Get restricts the value of the data set in the Form form to be ASCII characters; while Post supports the entire ISO10646 character set.
5, Get is the default method of Form.
Next Section