Latest web development tutorials

PHP $ _POST variables

In PHP, the predefined $ _POST variable is used to form from the method = "post" in the value of the collection.

$ _POST Variable

Forms predefined $ _POST variable is used to collect from the method = "post" in value.

Information form sent with the POST method from, for anyone not visible (not displayed in the browser's address bar), and on the amount of information sent is also not limited.

Note: However, by default, the maximum amount of information sent to the POST method 8 MB (can be changed by setting the php.ini file post_max_size).


form.html file code is as follows:

<meta charset="utf-8">

<form action="welcome.php" method="post">
名字: <input type="text" name="fname">
年龄: <input type="text" name="age">
<input type="submit" value="提交">


When the user clicks the "Submit" button, URL similar to the following:

"Welcome.php" file can now collect $ _POST variable to the form data (Note that the name of the form fields will automatically become $ _POST array keys):

欢迎 <?php echo $_POST["fname"]; ?>!<br>
你的年龄是 <?php echo $_POST["age"]; ?>  岁。

Demo accessed through a browser as follows:

When to use method = "post"?

Information from a form with the POST method of transmission, are not visible to anyone, and on the amount of information sent is also not limited.

However, since the tag is not displayed in the URL, it is not possible to bookmark this page.

PHP $ _REQUEST variable

Predefined $ _REQUEST variable contains the $ _GET, $ _ POST and content of the $ _COOKIE.

$ _REQUEST Variable can be used to collect form data sent via GET and POST methods.


You can "welcome.php" file is modified as follows the code, it can accept $ _GET, $ _ POST and other data.

欢迎 <?php echo $_REQUEST["fname"]; ?>!<br>
你的年龄是 <?php echo $_REQUEST["age"]; ?>  岁。