Problem with php receiving special character parameters such as + sign

不言
Release: 2023-03-23 17:38:01
Original
3022 people have browsed it

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.

1. Get method request

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.

2. Post request

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.

3. Conclusion

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template