Php $_POST & $_REQUEST variable

The $_POST Variable

The $_POST variable is used to collect values from a form which are sent using post method.
Information sent with the POST method is not visible to addressbar and it has no limitations

Note: There is default 8 Mb max size for the POST method it can be changed by setting the post_max_size in the php.ini file).

Example :

<form action="target.php" method="post">

Name: <input type="text" name="username" />

Age: <input type="text" name="country" />

<input type="submit" />
</form> 
When the user clicks the "Submit" button, the addressbar will be like this:
http://www.test.com/target.php 
The "target.php" file can now use the $_POST variable to collect form data (the names of the form fields will automatically be the keys in the $_POST array):

Welcome <?php echo $_POST["username"]; ?>!<br />

You are from  <?php echo $_POST["country"]; ?> country.

The PHP $_REQUEST Variable

The  $_REQUEST variable contain all values of  $_GET, $_POST, and $_COOKIE.
The $_REQUEST variable can be used to collect form data sent with both the GET and POST methods.

Example :

Welcome <?php echo $_REQUEST["username"]; ?>!<br />

You are from <?php echo $_REQUEST["country"]; ?> country.

No comments: