php cookie不更新 [英] php cookie doesn't update

查看:149
本文介绍了php cookie不更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要更新Cookie。我在一个php文件通过ajax调用。这是代码:

I need to update a cookie. I do that in a php file called via ajax. This is is the code:

setcookie('items['.$_POST['id'].']');

Cookie不会更新,实际上如果我写 print_r($ _ COOKIE ['items'])在setcookie函数后,我看到 $ _ COOKIE ['items'] 是在调用setcookie功能。

The cookie does not update, in fact if I write print_r($_COOKIE['items']) after the setcookie function I see that $_COOKIE['items'] is the same that was before the call to setcookie function. How can I do?

推荐答案

您不能在同一个实例/页面中设置和访问cookie。

You cannot set and access a cookie in the same instance/page. You have to do a redirect or refresh after setting it.

此外,您应该这样做:

setcookie("id","items['.{$_POST['id']}.']");

这篇关于php cookie不更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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