When defining the method a web browser should use to send variables to the page specified by your action, you either use GET or POST. Both send variables across to a page, but they do so in different ways.

GET sends its variables in the URL of your visitors' web browsers, which makes it easy to see what was sent. However, it also makes it very easy for visitors to change what was sent, and, moreover, there is usually a fairly low limit on the number of characters that can be sent in a URL - normally fewer than 250. As a result, if you send long variables using GET, you are likely to lose large amounts of it.

POST on the other hand sends its variables hidden to your user, which means it is much harder to mimic, cannot be changed without some effort on your visitors' behalf, and has a much higher limit (usually several megabytes) on the amount of data that can be sent. The downside to using POST is that browsers will not automatically re-send post data if your user clicks their Back button, leading to messages like "The data on this page needs to be resent", which often confuses users. This does not happen with GET, because browsers consider GET URLs the same as any other URL, and so happily re-send data as needed.

You can set how much data PHP should accept by editing the post_max_size entry in your php.ini file - it is usually set to 8M by default, allowing your users to transfer up to 8 megabytes.

Given this new found knowledge, here's the same form again, this time using action and method. It will still look the same as our previous effort, but this time it will use POST to send data to someform.php:

  <form="someform.php" method="post">

  <input type="submit" />



If this was helpful, please take a moment to tell others about Hacking with PHP by tweeting about it!

Next chapter: Available elements >>

Previous chapter: Designing a form

Jump to:


Home: Table of Contents

Copyright ©2015 Paul Hudson. Follow me: @twostraws.