$_GET method to step on the pit

background

When writing the code, I encountered a strange problem: the card and coupon decoding interface of the applet always reported that the decoding failed. After searching for an hour, I found that the url parameter was filtered out by the I method of thinkphp, and it involved PHP's native $ _GET

reason

The bottom layer of the I method is the native $_GET, and $_GET will use url_decode() to process the parameters first, and url_decode() will turn "+" into a space, as shown in the figure:

$_GET

url_decode

Solution

Write your own method to replace spaces back to "+"

private function convertSapceToPlus($str)
{
    return str_replace(' ','+',trim($str));
}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325682129&siteId=291194637