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.