The basics of GET & POST methods in PHP

When we want to transfer data in between clients & PHP servers, we are commonly using two HTTP methods.

  1. The GET method
  2. The POST method

In GET method, the browser encode our data with URL encoding & deliver it with our URL. But in POST method, the browser encode our data and deliver it via HTTP header of web pages.

Both are used for same application, to deliver data between clients and server. But an incorrect choice between them can lead to some unexpected and potentially harmful outcomes.

The GET method

  • The GET method send data via URL. So it create a long string with in our URL.
  • The safest length limit of web URLs are with in 2K. So we have a length limit to transfer data.
  • The GET method can’t be used to send binary data, like images or word documents, to the server.
  • We can’t use GET method to transfer sensitive data because its values are available in URL.
  • We can bookmark the URL generated by GET method & it can be usable for feature.
  • The URLs are always available in browser history untill we clear history.

The POST method

  • The POST method send data via HTTP header. So the values are not displayed in URL.
  • There is no restrictions or limit in the size of data. But 8 MB is the most preferable size.
  • The POST method don’t have any restrictions about file types. Binary data is allowed.
  • We can use POST method to transfer sensitive data because it is encoded & send via HTTP header.
  • The POST method Can not be bookmarked & cached.

In general, we can use GET method for insensitive data and queries that do not significantly alter our data in server. Same time, use the POST method with sensitive and large data.

Recent Posts

  1. Replace string in multiple files - Command line
  2. Solve Grunt error - Port 35729 is already in use by another process
  3. Install WP-CLI
  4. Install LAMP - Apache2 , MariaDB, PHP 7 on Debian 8
  5. Enable / Disable Magento 2 module using command line

Questions / Comments

If you found this article interesting, found errors, or just want to discuss about them, please get in touch. Send an email to & I like your words.