PHP url value transfer learning Notes 1. when the source code on the page is displayed in the browser, the browser will explain the HTML escape characters. Therefore, if special characters such as '& lt;', '& gt;' are to be displayed, in the source code, it can be & amp; lt; & amp; gt; 2. if you want to display the PHP url transfer value learning notes during echo display
1. when the source code on the page is displayed in the browser, the browser will explain the HTML escape characters. Therefore, if you want to display special characters, such as '<', '>, in the source code, it can be <> 2. if you want to display '<', '>' in PHP echo, you can process echo htmlspecialchars ('<>') in this way. htmlspecialchars can process the following characters '&', '"', ''', '<', '>' # '&' (ampersand) becomes '&' # '"' (double quote) becomes '"'When ENT_NOQUOTES is not set. # ''' (single quote) becomes ''' only when ENT_QUOTES is set. # '<' (less than) becomes' <'#'> '(greater than) becomes'> '3. the method echo "\ n" When you want to manually construct a url. however, to use the constructed url for js redirection, you cannot use htmlspecialchars (see figure 5 for details .) 4. IE and FireFox will Un_htmlspecialchars the href = "url" url (you can see it in the browser status bar after moving the cursor up) this is because html will automatically recognize entities like "&" and then perform the urlencode () variable during submission, and then submit the following content in PHP:-_.All other non-alphanumeric characters will be replaced with a semicolon (%) Followed by two hexadecimal numbers, and space is encoded as the plus sign (+). # Is special. if you want to transmit #, enter % 23 in the url bar or use the 3. method? 5. but in JS window. if the "&" character exists in the url of location = "url", it will not jump normally, the reason is that JS "&" only regards them as normal characters, but it will all perform urlencode () and then submit (you can see it in the browser status bar after moving the mouse up) therefore, when using PHP variables to embed url addresses in JS, pay special attention to 6. when a request is submitted, data is transmitted by urlencode () by the browser, whether it is the GET or POST method, and directly sent by PHP urldecode. Therefore, you do not need to process any urlencoding/urldecoding on your own. all of them are automatically processed. 7. if you want to send forms or data to the server in a browser, you can use the GET or POST method. The GET method uses the address bar of the browser to pass the value when accessing the URL. We can see this type of URL string on many websites. The GET method is convenient and intuitive. The disadvantage is that users who access the website can modify the URL string and send it to the server. if the program is not well processed, it is easy to make mistakes, in addition, the length of the string passed by GET cannot exceed 250 characters. if it is too long, the browser automatically truncates the string, leading to missing data. In addition, the GET method does not support any characters other than ASCII characters. for example, if the GET method contains Chinese characters or other non-ASCII characters, additional encoding is required, although sometimes the browser can also do it automatically (you can use the url_encode and url_decode functions ). When the POST method sends variable data, it is not transparent to users. for HTTP protocol, the data is appended to the header information and cannot be modified at will. for Web applications, the security is much better, and you can use POST to send large volumes of data to the Web server. Because POST is sent along with the HTTP header information, after the POST form is submitted, if the user clicks the "back" button when browsing the page, the browser will not automatically resend the POST data. If you click "refresh", a message "data has expired and whether to resubmit the form" is displayed, which is not as convenient as GET. When using GET to pass values, even if you use the "back" or "refresh" button, the URL address of the browser still exists. Therefore, in development, we need to flexibly select GET and POST based on actual applications to submit form data. It is worth mentioning that if the form end tag is missing in HTML, the entire form will not trigger any submission action. During actual development, some careless people will find that clicking the button does not reflect any. In fact, you can check the form code carefully. sometimes, even if you write less than one HTML character, browsers won't work for us either. 8. index. php? A = urlencode ('+'); urldecode ($ _ GET ['A']) = ''; urlencode encodes a space into a plus sign (+ ). Rawurlencode replaces a space with a semicolon (%) followed by two hexadecimal numbers. you can use rawurlencode () and rawurldecode () to avoid this error 9. urlencode () returns a string -_. all other non-alphanumeric characters will be replaced with a semicolon (%) followed by two hexadecimal numbers, and spaces will be encoded as the plus sign (+ ). This encoding method is the same as that for WWW form POST data and the same as that for application/x-www-form-urlencoded.