If you use the Base64_encode and Base64_decode methods directly, the resulting string may not be applicable to the URL address. The following methods can be used to resolve the problem:
URL-safe string encoding:
Copy the Code code as follows:
function Urlsafe_b64encode ($string) {
$data = Base64_encode ($string);
$data = str_replace (Array (' + ', '/', ' = '), array ('-', ' _ ', '), $data);
return $data;
}
URL-safe String decoding:
Copy the Code code as follows:
function Urlsafe_b64decode ($string) {
$data = str_replace (Array ('-', ' _ '), Array (' + ', '/'), $string);
$mod 4 = strlen ($data)% 4;
if ($mod 4) {
$data. = substr (' = = = ', $mod 4);
}
Return Base64_decode ($data);
}
The above describes the PHP security URL string base64 encoding and decoding, including the aspects of the content, I hope that the PHP tutorial interested in a friend helpful.