doumei1203 2014-11-19 14:37
浏览 132
已采纳

PHP _COOKIE没有设置,尽管它被设置在cookie头中

I can't quite figure this out, I am setting a cookie as follows in my PHP code.

setcookie('remember', $sCookie, time()+31557600, '/');

And I can clearly see it in the headers

Cookie:__utma=144618662.427039340.1410986461.1413382878.1413400525.42; __utmz=144618662.1412022114.19.3.utmcsr=unknown|utmccn=embed|utmcmd=embed; _ga=GA1.2.427039340.1410986461; remember=J%15%1C%009F%F0%0F%E6%24%C9%26%04%A8%3Ej8gp%2FLXjVo3AlCzFvO6em5A%3D%3D; PHPSESSID=pjaso28lsfkt16e9takc3s6q42

But if I var_dump($_COOKIES) all I get is

array(4) {
    '__utma' => string(55) "144618662.427039340.1410986461.1413382878.1413400525.42"
    '__utmz' => string(66) "144618662.1412022114.19.3.utmcsr=unknown|utmccn=embed|utmcmd=embed"
    '_ga' => string(26) "GA1.2.427039340.1410986461"
    'PHPSESSID' => string(26) "pjaso28lsfkt16e9takc3s6q42"
}

Other info

  • The domain is a development one, so the port is non-standard, 8888 instead of 80. As is the domain, commandstation.byl.dev.
  • I am running the exact same code on byl.dev:8888 and it works without issue.
  • If I look at the cookie info through a chrome plugin the host (commandstation.byl.dev) and path (/) are right.

Does anyone have any suggestions as to where I could look next to debug this issue?

  • 写回答

1条回答 默认 最新

  • duanjiao8871 2014-11-19 14:54
    关注

    I figured this out. The value I was storing to the cookie (which FYI was generated with openssl_encrypt) was not compatible with cookies.

    I base64 encoded the value after encrypting it and now it works fine. It was just a fluke that the encrypted string on the primary domain was acceptable, and for all I know it doesn't work for everyone so I will make the same fix there.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Python爬取指定微博话题下的内容,保存为txt
  • ¥15 vue2登录调用后端接口如何实现
  • ¥65 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?