Home > Backend Development > PHP Problem > What is the difference between get and post in php?

What is the difference between get and post in php?

青灯夜游
Release: 2023-02-27 07:30:01
Original
5441 people have browsed it

What is the difference between get and post in php?

The main difference between Get and Post is that Get transmits data through Url, while Post does not allow users to see the specific information transmitted. This difference determines the use of the two. The Get method is mainly used for searching, while the Post method is mainly used to transmit user operation information to the server. The following is the detailed difference between Get and Post:

Security of GET and POST

1. GET is requested through URL, which can be seen directly and transmitted in clear text.

2. POST is requested through the request header, which can be seen by developer tools or packet capture, and is also in clear text.

3. GET requests will be saved in the browser history and may also be saved in the Web log.

get submission, the requested data will follow the url (uniform resource positioning), low security

post submission, put the submitted data in the body of the http package, security High

Data size of GET and POST

GET: Certain browsers and servers have restrictions on URL length. For example, IE’s limit on URL length is 2083 bytes ( 2K 35). For other browsers, such as Netscape, FireFox, etc., there is theoretically no length limit, and the limit depends on the support of the operating system. The amount of data transmitted by Get is small because it is limited by the length of the URL, but it is more efficient;

POST: Because the value is not transmitted through the URL, the data is theoretically not limited. Post can transmit a large amount of data, so you can only use the Post method when uploading files;

The transmission data character format is different

get limits the value of the data set of the Form form to ASCII characters cannot be set through request.setCharacterEncoding("utf-8");. Chinese characters obtained by the server may be garbled!

post supports the entire character set ISO10646, and can display Chinese characters correctly through request.setCharacterEncoding("utf-8");.

The server side obtains data in different ways

Get is on the server side$_GET;

Post is on the server side$_POST

GET is idempotent, POST is not idempotent

Idempotence means that the same request method has the same effect if executed multiple times and executed only once.

1. According to RFC specifications, PUT, DELETE and security methods are idempotent. Although it is a specification, there is no guarantee whether the server implementation is idempotent.

2. The introduction of idempotence is mainly to deal with the situation where the same request is sent repeatedly, such as losing the connection before the request responds. If the method is idempotent, you can safely resend the request. This is also the reason why the browser will prompt the user when encountering POST when backing/refreshing: POST semantics are not idempotent, and repeated requests may bring unexpected consequences.

3. For example, in the scenario of Weibo, the semantics of GET will be used in the scenario of "Look at the latest 20 Weibo posts on my Timeline", while the semantics of POST will be used in the scenario of " In a scenario like posting on Weibo, commenting, and liking.

For more PHP related knowledge, please visit php中文网!

The above is the detailed content of What is the difference between get and post in php?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template