Scrambling problem of url encryption parameters acquired by php

1. base64_encode - Encoding data using MIME base64
In order to enable binary data to be transmitted through a non-pure 8-bit transport layer, such as the main body of e-mail.
Base64 requires that every three 8Bit bytes be converted to four 6Bit bytes (3*8 = 4*6 = 24), and then add two higher bits of 0 to the 6Bit to make up four 8Bit bytes, that is to say, the converted string will theoretically be one third longer than the original one.
Base64-encoded data takes up about 33% more space than the original data.
The encrypted string format is: upper and lower case letters, numbers, "+" number, "=" number and "/" number, and "=" number up to two.
base64 encoding url problem (reference):

//URL base 64 coding
function urlsafe_b64encode($string) {
    $data = base64_encode($string);
    $data = str_replace(array('+','/','='),array('-','_',''),$data);
    return $data;
}
//URL base 64 decoding
function urlsafe_b64decode($string) {
    $data = str_replace(array('-','_'),array('+','/'),$string);
    $mod4 = strlen($data) % 4;
    if ($mod4) {
        $data .= substr('====', $mod4);
    }
    return base64_decode($data);
}

2. base64_decode - Decoding data using MIME base64 encoding
3. rawurlencode - Code URL s according to RFC 3986
Before PHP 5.3.0, rawurlencode coded wavy lines (~) based on RFC 1738.
All non-alphanumeric characters except - in the string will be replaced by a percentage sign (%) followed by two hexadecimal digits.
4. rawurldecode - Decoding encoded URL strings
The sequence of percentiles (%) followed by two hexadecimal digits in the string will be replaced by the original character.
5. urlencode - encoding URL strings
All non-alphanumeric characters except - in this string will be replaced by a percent sign (%) followed by two hexadecimal digits, and spaces will be encoded by a plus sign (+). This encoding is the same as that of WWW form POST data, and the same as that of application/x-www-form-urlencoded media type encoding. For historical reasons, this encoding is compared with RFC3896 encoding in encoding spaces as plus sign (+).
6. urldecode - Decode encoded URL strings
Decode any% of the encoded string given. The plus sign ('+') is decoded into a space character.
Example:

$str = 'xia22wd';
$str2 = 'aHFZONlN2gkONRbUKCcM5y9Y+e2UbXK70JurgX3XcSU=';
//base64_encode, Base64 decode encryption and decryption
$base_enstr = base64_encode($str);
$base_destr = base64_decode($base_enstr);
//urlencode, urldecode conversion string
$urlen_str = urlencode($str2);
$urlde_str = urldecode($str2);
//rawurlencode, rawurldecode conversion strings
$rawurlen_str = rawurlencode($str2);
$rawurlde_str = rawurldecode($str2);

//Output the execution results of each function
echo '<b>str</b>: '.$str.'<br>';
echo '<b>base64_encode</b>: '.$base_enstr.'<br>';
echo '<b>base64_decode</b>: '.$base_destr.'<br>';
echo '<b>urlencode</b>: '.$urlen_str.'<br>';
echo '<b>urldecode</b>: '.$urlde_str.'<br>';
echo '<b>rawurlencode</b>: '.$rawurlen_str.'<br>';
echo '<b>rawurldecode</b>: '.$rawurlde_str.'<br>';

The result is:

str: xia22wd
base64_encode: eGlhMjJ3ZA==
base64_decode: xia22wd
urlencode: aHFZONlN2gkONRbUKCcM5y9Y%2Be2UbXK70JurgX3XcSU%3D
urldecode: aHFZONlN2gkONRbUKCcM5y9Y e2UbXK70JurgX3XcSU=
rawurlencode: aHFZONlN2gkONRbUKCcM5y9Y%2Be2UbXK70JurgX3XcSU%3D
rawurldecode: aHFZONlN2gkONRbUKCcM5y9Y+e2UbXK70JurgX3XcSU=

Tags: encoding PHP

Posted on Sun, 14 Apr 2019 22:39:32 -0400 by egiblock