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 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试
  • ¥20 问题请教!vue项目关于Nginx配置nonce安全策略的问题
  • ¥15 教务系统账号被盗号如何追溯设备
  • ¥20 delta降尺度方法,未来数据怎么降尺度
  • ¥15 c# 使用NPOI快速将datatable数据导入excel中指定sheet,要求快速高效
  • ¥15 再不同版本的系统上,TCP传输速度不一致
  • ¥15 高德地图点聚合中Marker的位置无法实时更新
  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题