iOS 全屏 Web 应用程序会丢弃 cookie?
我经历过,当您启动/退出保存到仪表板(全屏模式)的网络应用程序时,iOS4 会丢弃 cookie。
这是真的吗?有解决方法吗?
I have experienced that iOS4 drops cookies when you start/exits a web app saved to the dashboard (full screen mode).
Is it true and is there a workaround?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这不是一个错误,而是一个功能。会话 cookie(即生命周期为 0 的 cookie)会在浏览器会话结束时被删除 — 对于全屏 Web 应用程序,这种情况会在您离开 Web 应用程序时立即发生。如果您希望它们持续存在,只需将 cookie 生存期设置为大于默认值 0(我使用 1 年)即可。
现在您的问题可能是:如何设置 cookie 生命周期?假设您使用 PHP,则这段代码将是:
如果您使用 PHP 会话,则必须重写 cookie 以添加大于 0 的生存期:
通常,您不必在以下位置重写会话 cookie :为了更改默认生命周期,因为函数
session_set_cookie_params
应该让您这样做,但我发现情况并非总是如此。It's not a bug, it's a feature. Session cookies (i.e. cookies with a lifetime of 0) are dropped at the end of the browser session — which, in the case of a full screen web app, happens as soon as you leave the web app. If you want them to persist, just set your cookie lifetime to something larger than the default 0 (I use 1 year).
Now your question might be: how do I set my cookie lifetime? Assuming you're using PHP, the piece of code would be:
If you're using PHP sessions, you will have to rewrite the cookie to add a lifetime greater than 0:
Normally, you shouldn't have to rewrite the session cookie in order to change the default lifetime, as the function
session_set_cookie_params
should let you do just that, but I found it's not always the case.