PHP development basic tutorial $_POST
1. $_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).
Change the previous example to POST submission
Example: The code is as follows
<html> <head> <meta charset="utf-8"> <title>php中文网(php.cn)</title> </head> <body> <!-- 新建一个带有两个输入框和一个提交按钮的表单 --> <!-- action为提交的的那个页面,method为提交方式,有$POST和$GET两种 --> <form action="" method="post"> 名字: <input type="text" name="name"> <br/> 年龄: <input type="text" name="age"> <br/> <input type="submit" value="提交"> </form> <hr/> 大家好,我是 <?php echo $_POST["name"]; ?>!<br> 今年 <?php echo $_POST["age"]; ?> 岁。 </body> </html>
The output is as shown on the right
The page submitted to is 3_2.php, the code is as follows
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>php.cn</title> </head> <body> 大家好,我是 <?php echo $_POST["name"]; ?>!<br> 今年 <?php echo $_POST["age"]; ?> 岁。 </body> </html>
Note: You can observe the address bar to see if there is a query string. This is the difference between GET and POST
2. When to use method="post"?
Information sent from a form with the POST method is not visible 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.
3. PHP $_REQUEST variable
On the receiving page, in addition to using $_GET and $_POST to receive data , you can also use $_REQUEST to receive.
The predefined $_REQUEST variable contains the contents of $_GET, $_POST and $_COOKIE.
The previous two receiving statements can be combined into should. The code is as follows:
大家好,我是 <?php echo $_REQUEST["name"]; ?>!<br> 今年 <?php echo $_REQUEST["age"]; ?> 岁。
You can try it to see if it can be received normally