The difference between Setcookie and Setrawcookie
setrawcookie( 'jx_lang', rawurlencode( $str ), time() + 3600 );
Setrawcookie value plus rawurlencode and no difference
Reply content:
The difference between Setcookie and Setrawcookie
setrawcookie( 'jx_lang', rawurlencode( $str ), time() + 3600 );
Setrawcookie value plus rawurlencode and no difference
There is a passage in the Setcookie Handbook that describes:
Note that the value portion of the cookie would automatically be urlencoded if you send the cookie, and if it is receiv Ed, it is automatically decoded and assigned to a variable by the same name as the cookie name. If you don ' t want this, you can use Setrawcookie () instead if you are using PHP 5.
In other words setcookie
urlencode
, the cookie is encoded and setrawcookie
is not. So according to this, the question of the main problem is transformed urlencode
and rawurlencode
what is different, in general, the two main difference is only the coding protocol is not the same, according to search, I found this address: http://stackoverflow.com/questions/ 996139/urlencode-vs-rawurlencode. This is a detailed description of the difference between the two, you can refer to. The main reason is actually that +
and 空格
the code, HTTP://3V4L.ORG/15UDK in the case you can clearly reflect the difference. This note in the Setrawcookie manual also shows why it is needed in some scenarios urlrawencode
: http://php.net/manual/zh/function.setrawcookie.php#62848
$str = '123_,; abc';setcookie('test', $str, time()+60, '/');// value值:123_%2C%3B%20abcsetrawcookie('test1', $str, time()+60, '/');// value值:123_,; abcsetrawcookie('test2', rawurlencode($str), time()+60, '/');// value值:123_%2C%3B%20abcsetrawcookie('test2', encode_cookie_value($str), time()+60, '/');// value值:123_%2C%3B%20abc