Solution: Use js to encode the Chinese characters in the URL.
Copy codeThe Code is as follows:
<A href = "" onclick = "window. open ('product _ list. php? P_sort = '+ escape ('php development resource'); ">
The following figure shows the validity of the link:
Reference: http: // 127.0.0.1/shop/product_list.php? P_sort = PHP % u5F00 % u53D1 % u8D44 % u6E90 % u7F51
It is obvious that the urldecode () or base64_decode () of PHP cannot be reversed.
Solution: Use PHP to write an anti-solution function:
Copy codeThe Code is as follows:
Function js_unescape ($ str ){
$ Ret = '';
$ Len = strlen ($ str );
For ($ I = 0; $ I <$ len; $ I ++ ){
If ($ str [$ I] = '%' & $ str [$ I + 1] = 'U '){
$ Val = hexdec (substr ($ str, $ I + 2, 4 ));
If ($ val <0x7f) $ ret. = chr ($ val );
Else if ($ val <0x800) $ ret. = chr (0xc0 | ($ val> 6). chr (0x80 | ($ val & 0x3f ));
Else $ ret. = chr (0xe0 | ($ val> 12 )). chr (0x80 | ($ val> 6) & 0x3f )). chr (0x80 | ($ val & 0x3f ));
$ I + = 5;
}
Else if ($ str [$ I] = '% '){
$ Ret. = urldecode (substr ($ str, $ I, 3 ));
$ I + = 2;
}
Else $ ret. = $ str [$ I];
}
Return $ ret;
}
Note that JS encoding will be automatically converted to UTF-8, so the encoding must be converted to get the correct results, otherwise the Chinese garbled.
Copy codeThe Code is as follows:
Print iconv ('utf-8', 'gb2312', js_unescape ($ _ REQUEST ['P _ sort ']);
At this point, we have successfully reversed the js escape code.
In addition, I found a function that uses PHP to implement js escape encoding:
Copy codeThe Code is as follows:
Function phpescape ($ str ){
$ Sublen = strlen ($ str );
$ RetrunString = "";
For ($ I = 0; $ I <$ sublen; $ I ++ ){
If (ord ($ str [$ I]) >= 127 ){
$ TmpString = bin2hex (iconv ("gb2312", "ucs-2", substr ($ str, $ I, 2 )));
// $ TmpString = substr ($ tmpString,). substr ($ tmpString,); this option may be enabled in window
$ RetrunString. = "% u". $ tmpString;
$ I ++;
} Else {
$ RetrunString. = "%". dechex (ord ($ str [$ I]);
}}
Return $ retrunString;
}