发布于 1970-01-01 08:00
  • 2 个回答
    • 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 手册上的这个说明也表明了为什么在某些场景下需要使用 urlrawencodehttp://php.net/manual/zh/function.setrawcookie.php#62848

      2022-12-01 16:43 回答
    • $str = '123_,; abc';
      
      setcookie('test', $str, time()+60, '/');
      // value值:123_%2C%3B%20abc
      
      setrawcookie('test1', $str, time()+60, '/');
      // value值:123_,; abc
      
      setrawcookie('test2', rawurlencode($str), time()+60, '/');
      // value值:123_%2C%3B%20abc
      
      setrawcookie('test2', encode_cookie_value($str), time()+60, '/');
      // value值:123_%2C%3B%20abc
      
      2022-12-01 16:43 回答
    撰写答案
    今天,你开发时遇到什么问题呢?
    立即提问
    PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
    Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有