Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the use and difference between $_ GET and $_ POST variables in PHP

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly explains the "PHP $_ GET and $_ POST variable use and difference is what", the article explains the content is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in-depth, together to study and learn "PHP $_ GET and $_ POST variable use and difference is what" it!

In the previous article, we learned how to validate the required data and how to validate the mail and URL in the form through regular expressions. There is the shadow of the $_ GET variable and the $_ POST variable, so let's take a look at the knowledge about the use of the $_ GET variable and the $_ POST variable.

PHP $_ GET variable

We learned earlier that the $_ GET variable is used to collect values from the form from method= "get". Information sent from a form with the GET method is visible to anyone (it appears in the browser's address bar), and there is a limit to the amount of information sent. It can also be thought of as an array of variables passed to the current script through the URL parameter.

When you use the $_ GET variable, all variable names and values are displayed in URL. So you should not use this method when sending passwords or other sensitive information. However, because the variable is displayed in URL, you can favorite the page in your favorites. In some cases, this is very useful.

Let's take a look at this through an example:

(php.cn) name:

Gender: male and female

Age:

The content submitted to demo.php is:

Output result:

We found that the values we filled in the form were displayed in the Url column. So when do we use method= "get"?

When you use method= "get" in an HTML form, all variable names and values are displayed in URL. So you should not use this method when sending passwords or other sensitive information! However, because the variable is displayed in URL, you can favorite the page in your favorites. In some cases, this is very useful.

It should be noted that the HTTP GET method is not suitable for large variable values. Its value cannot exceed 2000 characters.

$_ POST variable

In the example above, we talked about the $_ GET variable, so let's take a look at the $_ POST variable, the predefined $_ POST variable used to collect values from the form from method= "post".

Information sent from a form with the POST method is invisible to anyone and does not appear in the browser's address bar like the $_ GET variable, and there is no limit to the amount of information sent. However, by default, the maximum amount of information sent by the POST method is 8 MB, which can be changed by setting post_max_size in the php.ini file.

Let's take a look at this through an example:

(php.cn) name:

Gender: male and female

Age:

The content submitted to demo.php is:

Output result:

We see that the information we submitted with POST is not displayed in the Url column, so POST is a little more secure than GET. Let's summarize the difference between $_ GET and $_ POST.

The difference between $_ GET and $_ POST

Get is to get data from the server, and post is to transfer data to the server.

Get adds the parameter data queue to the URL referred to in the ACTION attribute of the submitted form, and the value corresponds to each field in the form, which can be seen in URL. Through the HTTP post mechanism, post transmits each field in the form together with its contents in the HTML HEADER to the URL address referred to by the ACTION attribute. The process is not visible to the user.

For get mode, the server uses Request.QueryString to obtain the value of the variable, and for post mode, the server uses Request.Form to obtain the submitted data.

The amount of data transmitted by get is small and cannot be greater than 2KB. Post transmits a large amount of data and is generally regarded as unrestricted by default. But in theory, the maximum amount of IIS4 is 80KB and 100KB in IIS5.

The security of get is very low, while that of post is high. But the execution efficiency is better than the Post method.

Sort out the differences between the two into a table, as follows:

The display of $_ GET$_POST in url will be limited to the number of characters displayed in URL

It will not show that the amount of data submitted in URL is generally less than 2k. By default, PHP can submit a large amount of data of 8m. In terms of security, it is insecure and more secure. The data submitted is isolated and submitted as a whole. It is flexible to submit the data as a whole. If there is a page jump, you can transfer the data inflexibly. If you have to participate in the form, the common use is less than $_ GET.

Through the difference, we can draw the following conclusion:

The security of get is worse than that of Post. If confidential information is included, it is recommended to use Post data submission.

Get is recommended when querying data, while Post is recommended when data is added, modified or deleted.

Thank you for your reading, the above is the "PHP $_ GET and $_ POST variable use and difference is what" the content, after the study of this article, I believe you on the PHP of $_ GET and $_ POST variable use and what is the difference between what this problem has a deeper understanding, the specific use of the need for you to practice verification. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report