Home>Article>Backend Development> The difference between $_GET and $_POST in PHP

The difference between $_GET and $_POST in PHP

一个新手
一个新手 Original
2017-09-13 09:13:03 2312browse

$_GET and $_POST

post and get refer to: two ways of page submission

get: parameters are reflected in the url, which can be used for page turning and simple query. get can only receive content below 2k, so it has limitations. In addition, because the content is visible, security is reduced.

post: used for page form submission, file upload, and other operations. There is no size limit and it will not show up on the address bar.

$_POST variable

$_POST variable is an array containing the variable names and values sent by the HTTP POST method.

$_POST variable is used to collect values from the form with method="post".

The information sent from the form with the POST method is invisible to anyone (will not be displayed in the browser's address bar), and there is no limit on the amount of information sent

Why use $_POST?

Variables sent via HTTP POST will not appear in the URL.

There is no length limit for variables.

However, since the variable does not appear in the URL, the page cannot be bookmarked.

$_GET variable

$_GET variable is used to collect values from the form with method="get". Intuitively, it is the parameter that can be seen in the browser. For example, I am in Baidu When searching for "wordpress", the URL I requested was http://www.baidu.com/s?ie=utf-8&bs=wordpress&f=8&rsv_bp=1&wd=wordpress&inputT=0, then the parameters after '?' are all OK Use $_GET to obtain, each parameter is separated by '&'.

$_GET variable is an array containing the variable names and values sent by the HTTP GET method.

The information sent from the form with the GET method is visible to anyone (will be displayed in the browser's address bar), and there is a limit on the amount of information sent (up to 100 characters). Therefore, the length of the parameters is not infinite, but it can basically meet our requirements.

Why use $_GET?

Note: When using the $_GET variable, all variable names and values will be displayed in the URL. So this method should not be used when sending passwords or other sensitive information. However, because the variables appear in the URL, you can bookmark the page. In some cases, this is useful.

Note: The HTTP GET method is not suitable for large variable values; the value cannot exceed 100 characters.

****The difference between $_POST and $_GET:

1. The former can not see the transmitted content in the URL column, while the latter You can see the content in the column of the URL

2. The Get method needs to use Request.QueryString to get the value of the variable; while the Post method uses Request.Form to access the submitted content

3. The size of the content transmitted by the former is relatively large, the security is relatively high, and the execution efficiency is slightly lower; the upload size of the latter is relatively small, the security is low, and the execution efficiency is slightly higher

4 , Submitting data through Get method will bring security issues, such as a login page. When submitting data through Get method, the user name and password will appear on the URL. If the page can be cached or other people can access the customer's machine, it can The user's account and password are obtained from historical records, so it is recommended to use the Post method for form submission; a common problem with form pages submitted using the Post method is that if the page is refreshed, a dialog box

Request will pop up. Form and Request.QueryString receive parameters from different sources. The former receives parameters from the form, while the latter receives parameters from the URL.

Request.Form: Get data submitted in POST mode (receive data submitted by Form);

Request.QueryString: Get address bar parameters (data submitted in GET mode)

The above is the detailed content of The difference between $_GET and $_POST in PHP. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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