HTML Old School

POST vs GET

There are several methods for sending variables from browser (HTML form) to the server (PHP script).

The most importanat are:

  • GET - send variables via URL
  • POST - send variable via HTTP Header

 

GET

- variables are visible in URL: /dir/script.php?var1=value1&var2=value2

- URL can have only 2048 characters

- variables saved in browser history and can be bookmarked

- can be cached

Example: 35formmethod_get.html

PHP script with $_GET: 35script.php

 

Notice that empty string (space) in variable value will be replaced with + in the URL:

script.php?var1=some+string   or

script.php?var1=++++some+++string+

 

 

POST

- variables are sent via HTTP header

- variables are not saved in browser history, and can't be bookmarked

- can't be cached

Example: 36formmethod_post.html

PHP script with $_POST: 36script.php

 

 

 

Some rules

 1. When you want to send subject and body to email client always use GET. Method POST will not work.

Example with mailto : 37formmethod_email.html

 

 2. When you want to upload file to the server always use POST.

 Example: 08file_multiple.html