• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

setcookie 与 setrawcookie 的区别

php 搞代码 4年前 (2022-01-26) 40次浏览 已收录 0个评论
文章目录[隐藏]

setcookie 与 setrawcookie 的区别

<code>setrawcookie( 'jx_lang', rawurlencode( $str ), time() + 3600 );</code>

setrawcookie给 值 加上rawurlencode与不加的区别

回复内容:

setcookie 与 setrawcookie 的区别

<code>setrawcookie( 'jx_lang', rawurlencode( $str ), time() + 3600 );</code>

setrawcookie给 值 加上rawurlencode与不加的区别

setcookie 手册上有一段话是这么描述的:

Note that the value portion of the cookie will automatically be urlencoded when you send the cookie, and when it is received, 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.

也就是说 setcookie 是用了 urlencode 对 cookie 进行编码了的,而 setrawcookie 是没有的。那么根据这个,题主的问题也就转化成了 urlencoderawurlencode 有什么不同了,总的来说这两个主要的差别只是编码协议的不一样而已,根据搜索,我找到了这个地址:http://stackoverflow.com/questions/996139/urlencode-vs-rawurlencode 。这上头详细的描述了这两者的区别,你可以参考一下。主要的原因其实还是那个+空格 的编码,http://3v4l.org/15udk 在实例上你能清楚的体现区别。setrawcookie 手册上的这个说明也表明了为什么在某些场景下需要使用 urlrawencode:http://php.net/manual/zh/function.setraw%本文@来源gao@!dai!ma.com搞$$代^@码!网搞代gaodaima码cookie.php#62848

<code>$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</code>

搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:setcookie 与 setrawcookie 的区别
喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址