GET and POST values in PHP dynamic development

Source: Internet
Author: User
As we all know, we often have this kind of requirement. we hope to pass the value from one page to another. for example, on the Baidu homepage, we search for keywords and submit the keywords to jump to the search content page. Introduce

As we all know, we often have this kind of requirement. we hope to pass the value from one page to another. for example, on the Baidu homepage, we search for keywords and submit the keywords to jump to the search content page. First, we will introduce the following:

GET value transfer: it is generally passed through the URL parameter, we have a common URL following ?, A lot of parameters and values are followed. this is the result of passing parameters through the GET method. we have the predefined variable $ _ GET to implement passing values, all URL parameter names are indexes of an array element in the $ _ GET array. the code is as follows:
// The method for passing parameters. add the following after the URL of the page :? Keywords = hello
$ GetKeywords = $ _ GET ["keywords"]; // receives the keywords parameter passed by the GET method.
If (empty ($ getKeywords )){
Echo "the passed parameter is null or no parameter is passed ";
} Else {
Echo $ getKeywords;
}

After the URL? Keywords = hello test. Separate multiple parameters. Of course, this is only a test. you will not need to enter these parameters and values by yourself. in specific usage, we will put the GET value in the tag. when we click it, we will pass the parameter over. Such as login_deal.php? Act = in.

Garbled problem: urldecode () decoding. Urlencode () encoding. Specific usage: Go to Baidu.

POST value transfer: this is implemented using the $ _ POST array, which is usually used in forms. at least I think the form must use POST, which is related to security issues. The name attribute in each form is the index of the $ _ POST array, and the corresponding value is accessed through $ _ POST ["name.

Differences between POST and GET values:
Similarities: both the POST method and GET method can be used to obtain the passed values on the page.
Difference: GET: the submitted data type is text, and POST: can be text and binary data.
GET: there is a limit on the length of the value to be passed, but there is no POST.
The URL of the message submitted by GET is visible, and the POST is invisible.
The GET value will be cached by the browser, and the POST will not.
GET execution efficiency is fast, but the security is poor; POST execution efficiency is slow, but the security is good.
Generally, POST is used to pass values in a form, and GET can be used to pass values in an action parameter.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.