Bluehost(或 PHP 脚本)的 Cookie 问题
我在 Cookie 方面遇到了最奇怪的问题。我编写了一些 PHP 脚本,它使用令牌来识别访问者,以便“他/她”可以正确使用该网站。
Token 系统在本地开发机器(windoze+ZendApache)上运行良好,但在 Bluehost 上的生产服务器上不起作用。
当设置 cookie 的有效期为 60 天时,我使用“/”作为路径,使用“mydomain.com”作为域。我可以正确地在浏览器上看到 cookie,并且与数据库中的值相比,我可以确认这些值设置正确。
每次刷新页面时,服务器不会获取 cookie,而是创建一个新令牌并将其发送回浏览器,并再次在数据库中创建新记录。新的 cookie 再次与最新记录匹配,但下次刷新时,又会出现同样的情况。无法维护令牌,因此无法浏览该网站。
知道为什么会发生这种情况吗?有没有可能我错过了一些设置?
我已经在最新的 Firefox、Opera、Safari 和 Chrome 上对其进行了测试。
谢谢。
编辑:
这是一个 PHP & Bluehost 相关问题,我以序列化格式将 3、40 个字符的字符串存储在 cookie 的值上。由于某种原因,unserialize() 函数没有在 Bluehost 上执行,但在我的开发机器上运行良好。所以我将存储的值更改为40chars.40chars.40chars,并用分隔符“.”分解该值。得到3个字符串。
再次感谢。
I've got the weirdest problem with Cookies. I've written some PHP script that uses tokens to identify the visitor so that "he/she" can use the website correctly.
The Token system is working perfectly on the local development machine (windoze+ZendApache) and doesn't work on the production server, which is on Bluehost.
I use "/" for path and "mydomain.com" for the domain when setting the cookie with an expiry of 60 days. I can see the cookies on the browser correctly and I can confirm that the values are set correctly when compared to the values in the database.
Every time the page gets refreshed the server doesn't get the cookie and creates a new token and sends it back to the browser and is creating a new record in the database again. The new cookie matches the latest record again, but next time I refresh, same thing all over again. Can't maintain the token, so navigating the site is impossible.
Any idea why this is happening? Is it possible that I've missed some setting?
I've tested it on latest Firefox, Opera, Safari and Chrome.
Thanks.
EDIT:
It is a PHP & Bluehost related issue, I was storing 3, 40-character strings on the value of the cookie in serialized format. The unserialize() function wasn't executing for some reason on Bluehost but was running fine on my dev machine. So I changed the stored value to 40chars.40chars.40chars and exploded the value with the delimiter "." to get the 3 strings.
Thanks again.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你应该使用
而不是
例如:
you should use
instead of
for example: