The difference between Setcookie and Setrawcookie

Source: Internet
Author: User
Tags setcookie
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
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.