When using PHP to do something, found a problem, can be easily attributed to the problem of garbled, but this problem is not the function itself caused. To see who the culprit is.
Suspects: Base64_encode and Base64_decode
Crime: I wrote a jump and prompt function, after receiving the prompt message to jump to the specified page, but jump prompt when the Chinese characters garbled.
The jump template code is as follows:
Copy CodeThe code is as follows:
<title>Jump Tips</title>
<?php if ($_get[' success ') {?>
:) Congratulations!
<?php Echo base64_decode ($_get[' message ');?>
<?php}else{?>
:( It's a mistake!
<?php Echo base64_decode ($_get[' message ');?>
<?php}?>
The system will be in <?php echo $_get[' time ';?> after the jump, can be directly "> point this jump
The PHP redirect function is defined as follows:
Copy the Code code as follows:
/* Reminder after jump */
function _alert ($success =true, $message = ' success ', $time = ' 3 ', $url = '/') {
Header (' location:/include/redirect.php?success= '. $success. ' &message= '. Base64_encode ($message). ' &time= '. $time. ' &url= '. Base64_encode ($url));
Exit
}
If you call the function in PHP like this:
Copy the Code code as follows:
$query = "Update content set bid= ' $clean [bid] ', title= ' $clean [title] ', content= ' $clean [content] ', path= ' $clean [path] ' Where id= ". $clean [' id '];
if (mysql_query ($query)) {
_alert (1, ' Modified Success ', 3, '/admin/manage.php ');
}else{
_alert (False, ' modify failed '. Mysql_error (), 5, '/admin/manage.php ');
}
You will see that the words "modified successfully" or "modified failed" are garbled characters.
Why?
Sometimes with Base64_encode encryption, in the form of get to other pages, with Base64_decode decryption, there is garbled.
When I encounter this problem, I wonder why some of them can be decrypted correctly, but some of them are garbled.
Later after the inspection, found that there are some Chinese characters, in the form of Get pass, the + number will be replaced by a space.
In order to prevent garbled situation, I did a step to replace, and then decrypt, sure enough, garbled problem, no longer exist!
Now the problem is very simple, just write one more step.
Copy the Code code as follows:
$str = Base64_decode (Str_replace ("", "+", $_get[' str '));
Originally, the article first set the wrong suspect, wronged the two functions ...
You can also refer to this article: PHP secure URL string base64 encoding and decoding
http://www.bkjia.com/PHPjc/825406.html www.bkjia.com true http://www.bkjia.com/PHPjc/825406.html techarticle when using PHP to do something, found a problem, can be easily attributed to the problem of garbled, but this problem is not the function itself caused. To see who the culprit is. Suspect: ...