Cookie未在PHP中设置 [英] Cookie not setting in PHP

查看:47
本文介绍了Cookie未在PHP中设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这认为超级简单,但是我花了最后半个小时试图弄清楚这没有用。

Thought this was super easy, but I've spent the last half hour trying to figure it out to no avail.

$unique_id = uniqid(microtime(),1);

if (is_null($_COOKIE['client_id']))
  {
  setcookie("client_id", $unique_id);
  }

但是当我通过$ _COOKIE检查cookie时[ client_id'],则返回空值。有什么想法吗?

推荐答案

已创建_COOKIE数组脚本初始化时,然后由PHP单独保留。在脚本中设置cookie不会神奇地将其添加到$ _COOKIE。它只会显示在下一个脚本请求中,或者您将其手动分配给$ _COOKIE。

The _COOKIE array is created when the script initializes, and is then left alone by PHP. Setting a cookie within the script will not magically add it to $_COOKIE. It will only show up on the next script request, or you manually assign it into $_COOKIE.

这篇关于Cookie未在PHP中设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆