Your Favorite Color: Post and Get

  1. Email
  2. Your Favorite Color
  3. The final code

There are several “methods” that you can use to send your form data to the server for PHP to parse. Two of the most common are “post” and “get”. The get method is very useful if you want your visitors to be able to come back to the results page. For example, if your form searches rooms in a building, you might use get to allow them to bookmark a specific building. Or if you are providing a form that lets them search a list of classes by topic, you might use get so that they can bookmark the topic and come back to it later to see if there are any new classes in that topic.

The get method also allows them to copy the URL out of their web browser and send it by e-mail. So they could, for example, look up classes on a topic and then e-mail a link to the results to a friend. Search engines often use the get method. This allows visitors to bookmark their searches, and it allows them to send the search results to friends and colleagues.

The “post” method is not bookmarkable. You should use post if you do not want the user to be able to “come back” to this page. For example, if they are purchasing something you don’t want them to submit the purchase twice. If they are deleting something from your database, coming back a second time will probably just result in an error; if they are inserting something into your database, they may end up inserting it twice if you aren’t careful with your PHP code.

Posted information is also more private. Because get information is part of the URL it is also stored in the web server’s logs. Anyone who can see those logs can see the form information. Even if the server itself is a secure server, get information is still posted to the logs. If your form submissions include secure or private information, you should use post to submit them.

If your forms accept a lot of data, you will need to use a post form. Web browsers and web servers can “truncate” get submissions. The limit on the size of a get submission is highly variable but the general recommendation is that if the form data is likely to approach 1,024 bytes, go with the post method. This is probably part of the reason that search engines, which want to be bookmarkable, will abbreviate their form fields to two-letter or one-letter fieldnames.

If your form is method="get" you’ll use $_GET instead of $_POST to get the submitted values.

  1. Email
  2. Your Favorite Color
  3. The final code