Hudzilla.org - the homepage of Paul Hudson
Contents > HTML Forms > Designing a form Wish List | Report Bug | About Me ]

7.3.1     GET and POST

This is NOT the latest copy of this book; click here for the latest version.

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 ACTION="someform.php" METHOD="POST">

<INPUT TYPE="submit" />

</FORM>





<< 7.3 Designing a form   7.3.2 Available elements >>
Table of Contents
Want to see this stuff in print? PHP in a Nutshell takes the core topics covered here, adds in thousands of edits from the editorial team and myself, and combines them to make an unbeatable reference for PHP programmers at all levels.



My latest book has hundreds more tips on how to use PHP, Apache, and MySQL, plus Perl, Python, shell scripts, performance tuning, and more!



Top-right shadow
 
Bottom-left shadow Bottom shadow

Comments from other readers
A PHP User - 30 Aug 2008

The statement

"there is usually a fairly low limit on the number of characters that can be sent in a URL - normally fewer than 250"

is not true in modern browsers. Last time I checked (around 1999-2000 timeframe) IE 5.0x on Windows had a limit of around 2.8K characters, and Netscape 4.x had a limit closer to 4K.

However, many web *servers* have a shorter limit for how many characters they will accept in a URL. This varies by web server, so I agree with the general statement that you shouldn't use GET to send large amounts of data.

A PHP User - 30 Aug 2008

$_GET['name']
$_POST['name']

Emanuele Ciriachi - 30 Aug 2008

In this page I was hoping to find something which tells me how to use the variables sent using GET...



Add comment
Please note that by posting a comment here you are committing it to the public domain. This is important so that others can make use of your code themselves, and also so that I can incorporate helpful notes directly into the main text. Comments are limited to 2000 characters in length.

If you are reporting an error in the content, please tell me directly.

Your name/email address:
Your comment:
 
Now, in order to verify that you're a real person, please answer this simple question: what is six plus three?
The answer is:
(please write in
numbers, eg 19)


Top-right shadow
 
Bottom-left shadow Bottom shadow