PHP无法读取Cookie? [英] PHP Can't read cookies?

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

问题描述

我喜欢使用PHP查看是否存在 COMPLETE 的cookie PHPSID27258STATUS

I like to use PHP to see if a cookie PHPSID27258STATUS is present with the value COMPLETE en if so do stuff.

在Google Chrome中(在选项中)我可以看到这个cookie存在,值为 COMPLETE

In google chrome (in Options) I can see this cookie is present and has the value COMPLETE.

如果我运行这个PHP脚本,我得到'未设置'。我在这里做错了什么?

If I run this PHP script I get 'Not Set'. What am I doing wrong here?

$cookiename="PHPSID27258STATUS";
if (isset($_COOKIE[$cookiename]) && $_COOKIE[$cookiename] == "COMPLETE")

- 更新

Cookie由开放源代码调查平台limesurvey设置。虽然它可能不是最好的方法。我使用limesurvey有一个小调查(iframe)在我正在建设的网站。我喜欢让调查在下次访问时消失,当它有bin张贴。
Limesurvey从同一个主机运行(localhost now)。并且在网站的子目录中。

--update
The cookie is set by "limesurvey" an open source survey platform. Although its probably not the best way. I use limesurvey to have a small survey (iframe) on an site i'm building. I like to let the survey disappear on the next visit when it has bin posted. Limesurvey runs from the same host (localhost now). And is in a sub directory of the site.

我想(但LS中有很多代码)这是如何在轮询/已完成。

I guess (but there's a lot of code in LS) this is how the cookie is made after an poll/post is completed.

$cookiename="PHPSID".returnglobal('sid')."STATUS";
setcookie("$cookiename", "COMPLETE", time() + 31536000); //Cookie will expire in 365 days


推荐答案

读取与读取脚本属于同一域的Cookie。例如,如果cookie PHPSID27258STATUS由域xyz.com设置,您不能使用abc.com上的脚本读取它。因此,请确保您所需的cookie的域是相同的。

You can only read cookies which belong to the same domain as the reading script. For instance if the cookie PHPSID27258STATUS was set by domain xyz.com, you can not read it using a script on abc.com. So make sure the domain of your desired cookie is the same. Also show us the code part where you are setting your cookie.

编辑:

setcookie($cookiename, "COMPLETE", (time() + 31536000) , '/');

这篇关于PHP无法读取Cookie?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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