Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

PHP $_POST Variable

PHP $_POST Variable


In PHP, the predefined $_POST variable is used to collect values from a form with method="post".


$_POST variable

The predefined $_POST variable is used to collect values from a form with method="post".

Information sent from a form with the POST method is invisible to anyone (it does not show 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 (which can be changed by setting post_max_size in the php.ini file).

Example

form.html The file code is as follows:





Runoob Tutorial(runoob.com)



名字: 年龄:

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

http://www.runoob.com/welcome.php

The "welcome.php" file can now collect the form data via the $_POST variable (note that the form field names automatically become the keys in the $_POST array):


欢迎 !
你的年龄是 岁。

The demonstration via browser access is as follows:


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, because the variables are not displayed in the URL, the page cannot be bookmarked.


PHP $_REQUEST Variable

The predefined $_REQUEST variable contains the contents of $_GET, $_POST and $_COOKIE.

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

Example

You can modify the "welcome.php" file to the code below, which can accept $_GET, $_POST and other data.


欢迎 !
你的年龄是 岁。