PHP receive + number and other special character parameters of the problem

Source: Internet
Author: User
Tags html form

This article introduces the content of PHP receive + number and other special character parameters of the problem, now share to everyone, the need for friends can see

Record a somewhat strange question about whether the parameter "+" is escaped during transmission.

1. Get method Request

Using the Get method, PHP receives the parameter "+" will become a space, see the description should be executed UrlDecode, if need to revert to "+" sign, need to connect to the parameters received UrlEncode.
By using Curl and browser, the received parameter turns the + sign into a space.
The request address is http://ip/xx?aa=+889
Using the $_REQUEST['aa'] received parameter value is “ 889” , the parameter + number is converted to a space, if you want to get the original +889 , you need to use urlencode($_REQUEST) to get.

However, if the transmission, the use, that is http://ip/xx?aa=%2B889 , the + number is the URL encoding, then $_REQUEST received is +889 the parameter.

2. Post Method request

Using the Post method, curl performs the received parameter and turns the + sign into a space, but the post received by the HTML form is the full + number (the parameter is automatically URL encoded when the form is submitted). )。
The receive parameter uses $_post.
If the parameters of the post are encoded after curl, %2B889 then PHP receives the +889 .

3. Conclusion

Therefore, a conclusion is drawn:
PHP will automatically urldecode the parameter once it receives the parameter, so if the passed parameter is not URL-encoded, the special character (for example, +) will be decoded to a space, causing the parameter to be received incorrectly.
If you want PHP to correctly receive parameters that contain special characters, there needs to be a contract between the client and the server, such as the parameters sent by the client are URL-encoded parameters, so that the parameters that the server receives are the correct parameters.

Related Article

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.