This article introduces the problem of PHP receiving special character parameters such as numbers. Now I share it with everyone. Friends in need can take a look.
Record a somewhat strange problem, regarding the parameter " " Whether it is escaped during transmission.
Using the get method, the " " in the parameters received by php will become a space. From the instructions, it should be that urldecode has been executed. If it needs to be restored to the " " sign, The received parameters need to be urlencoded.
By using curl and browser methods, all parameters received are converted into spaces.
The request address is http://ip/xx?aa= 889
Use $_REQUEST['aa']
The 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 obtain it.
However, if http://ip/xx?aa=+889
is used during transmission, that is, the number is url encoded by itself, then $_REQUEST
What is received is the parameter of 889
.
Using the post method, the parameters received by curl execution also convert the number into spaces; however, when the post is simulated through the html form, the complete number is received. (The parameters are automatically URL-encoded when the form is submitted?).
Use $_POST to receive parameters.
If during curl, the post parameter uses the encoded +889
, then php will receive 889
.
Therefore, we draw a conclusion:
When php receives the parameters, it will automatically perform a urldecode decoding operation on the parameters. Therefore, if it is transmitted The parameters are not URL-encoded, and special characters (such as numbers) will be decoded into spaces, resulting in incorrect parameter reception.
If you want PHP to correctly receive parameters containing special characters, then there needs to be an agreement between the client and the server. For example, the parameters sent by the client are all URL-encoded parameters, so that the server receives The parameters are the correct parameters.
The above is the detailed content of Problem with php receiving special character parameters such as + sign. For more information, please follow other related articles on the PHP Chinese website!