使用 php setcookie() 创建并通过 AJAX 和 XMLHttpRequest 调用的 Cookie 在 Firefox 重新启动时消失

发布于 2024-08-04 20:15:31 字数 368 浏览 1 评论 0原文

我正在制作一个简单的ajax登录系统,使用cookie来记住用户名或在下次访问时自动登录。一切正常,cookies 设置为未来 10 天,当我查看 Firefox 的 cookie 时可以看到它们,但当我重新启动浏览器时它们会被删除。 cookie 是通过使用 jQuery .get 函数调用的 php 脚本中的 setcookie() 设置的。我也尝试过 .post 但同样的情况发生。 Firebug 正确报告 Set-Cookie 标头。 我在本地主机上尝试过,在真实的服务器上,我尝试将所有参数传递给 setcookie() 因为我读到了一些内容,如果不这样做,Firefox 会将其视为会话 cookie,我在主机名上尝试了 2 个点以及所有可能的解决方案我可以在网上找到。我不明白为什么它不起作用......

I'm making a simple ajax login system using cookies to remember username or login automatically on the next visit. Everything works ok, the cookies are set 10 days to the future, I can see them when I go and see Firefox's cookies but they are deleted when I restart the browser.
The cookies are set with setcookie() from a php script called using jQuery .get function. I tried .post too but the same happens. Firebug reports the Set-Cookie header correctly.
I tried it on localhost, and on a real live server, I tried passing all the parameters to setcookie() because I read something that Firefox treats it as session cookie if you don't, I tried 2 dots on hostname and every possible solution I could find on the net. I don't see why it doesn't work...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

素罗衫 2024-08-11 20:15:31

您尝试过其他浏览器吗?可能是您将 Firefox 配置为在每次关闭时删除 Cookie。

采取以下步骤:

  1. 根据您的操作系统单击选项或首选项。
  2. 单击隐私
  3. 取消选中“始终清除我的私人数据”。

have you tried any other browser? it could be that you configured your firefox to delete cookies every time it is closed.

take following steps:

  1. click options or preferences depending on your OS.
  2. click privacy
  3. un check "Always clear my private data".
墟烟 2024-08-11 20:15:31

好吧,似乎它只发生在我的浏览器上,可能是因为它是 Firefox 便携式的。

Ok seems like it happens only on my browser, probably it's because it's Firefox portable.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文