Easy Tutorial
❮ Func Ftp Raw Func String Explode ❯

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 others (it does not display in the browser's address bar) and has no limits on the amount of information to send.

Note: However, by default, the maximum amount of data sent with the POST method is 8 MB (this can be changed by setting post_max_size in the php.ini file).

Example

The form.html file code is as follows:

<html>
<head>
<meta charset="utf-8">
<title>tutorialpro.org(tutorialpro.org)</title>
</head>
<body>

<form action="welcome.php" method="post">
Name: <input type="text" name="fname">
Age: <input type="text" name="age">
<input type="submit" value="Submit">
</form>

</body>
</html>

When the user clicks the "Submit" button, the URL looks like this:

http://www.tutorialpro.org/welcome.php

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

Welcome <?php echo $_POST["fname"]; ?>!<br>
Your age is <?php echo $_POST["age"]; ?> years old.

The demonstration in the browser looks like this:


When to Use method="post"?

Information sent from a form with the POST method is invisible to others and has no limits on the amount of information to send.

However, since the variables are not displayed in the URL, it is not possible to bookmark the page.


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 with both GET and POST methods.

Example

You can modify the "welcome.php" file to accept data from $_GET, $_POST, etc., with the following code:

Welcome <?php echo $_REQUEST["fname"]; ?>!<br>
Your age is <?php echo $_REQUEST["age"]; ?> years old.
❮ Func Ftp Raw Func String Explode ❯