PHP Tutorial – $_POST Function

The PHP built-in $_POST function is used to collect values in a form (as name says, you do this with the method=”post”) The information send with POST method is invisible to others (the opposite of the GET method.)

Another difference between the $_GET function and the $_POST function is that the $_POST function doesn’t limit the amount of information that you want to send. (Limit of $_GET is 100 characters.) But you should be aware of the following: by default there is an 8Mb maximum size for the post method. (If you want a larger size you can change it in the php.ini file. The setting is called post_max_size.)

Let’s look at an $_POST example:


<html>
<body>

<form action="test.php" method="post">
Your name: <input type="text" name="yourname" />
<input type="submit" />
</form>

</body>
</html>

If the user clicks on the submit button, the URL called will look like this:


http://www.codingunit.com/test.php

The names of the form fields will automatically be the keys in the $_POST array. So we can use the name “yourname” in the PHP file test.php. For example we can do this:


Welcome <?php echo $_POST["yourname"]; ?>!

That’s all for this tutorial.

This entry was posted in PHP Tutorials. You can follow any responses to this entry through the RSS 2.0 feed. Both comments and pings are currently closed. Tweet This! Tweet This! or use to share this post with others.

There are currently 5 responses to “PHP Tutorial – $_POST Function”

Why not let us know what you think by adding your own comment!

  1. Ridip on March 8th, 2011:

    nice. helpful

  2. Pokaran on September 28th, 2011:

    Nice website and very much useful, helped me understanding the basic concept of $_POST function.

    Thanks

  3. Animesh Chandra Bain on March 25th, 2012:

    very helpful tor the basic php learner

  4. Simon's Reyes Blogs on June 11th, 2012:

    Thanks for sharing…

  5. Foroz farhat on February 25th, 2013:

    Thanks nice. helpful