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.
- The GET method
- 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.
- Solve "ValueError invalid literal for int() with base 10" - Python
- Handling dynamic subdomain with Flask - Python
- A minimal example about WordPress object cache
- Select random element from a list - Python
- Write our first Selenium program with Python 3 & Firefox
Your Questions / Comments
If you found this article interesting, found errors, or just want to discuss about it, please get in touch.