About the difference between GET and POST

table of contents
Nice to meet you! My name is Hase and I joined the development team as a new graduate this year.
In this article, I would like to explain the difference between "GET" and "POST" which are used to transfer information in PHP for those new to programming.
What are GET and POST?
This refers to the method used when transferring data such as input forms to a web server
GET Features
- The data is added after the URL and sent
- Since the data is written in the URL, the data you enter can be seen by others
- Because the number of characters that can be used in a URL is limited (Internet Explorer allows a maximum of 2,048 characters in a URL), the amount of data that can be sent is also limited
- Only text data can be sent (binary data such as image data cannot be sent as it cannot be written in a URL)
Example: http://localhost/sample/confirm.php?name=%E5%B1%B1%E7%94%B0%E5%A4%AA%E9%83%8E&age=22
The "?" marks the beginning of the parameter.
The "&" separates the parameters.
The left side of the "=" is the GET variable name, and the right side is the value to be passed.
The value to be passed is %E5%B1%B1%E7... because Japanese characters have been converted. (Japanese characters cannot be used in URLs.)
POST Features
- The data is not added to the URL
- Since the data is not written in the URL, it cannot be seen by others
- There is no limit to the amount of data that can be sent
- Both text and binary data can be sent
Example: http://localhost/sample/confirm.php
When to use GET or POST
Use POST if the following applies
When there is a large amount of data
As mentioned above, Internet Explorer limits the maximum number of characters that can be used in a URL to 2,048 characters, and
in the case of GET, the data is added to the end of the URL and sent, so the amount of data that can be sent is limited.
Therefore, if the amount of data is large, use POST.
When sending confidential information
If the data contains information you don't want to share with others, such as an email address or password,
using GET will add the data information after the URL, making it visible to others.
Therefore, if you want to send confidential information, use POST.
When sending binary data
Use POST when sending binary data such as images
At the end
If you want to share data via a URL, you can use GET if you don't mind others seeing the data.
However, you should always use POST if the form contains personal information, such as a form for entering personal information or ordering products.
That's all.
0