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.