iPhone“书签到主屏幕"删除cookies和会话? [英] iPhone "Bookmark to Homescreen" removes cookies and session?

查看:24
本文介绍了iPhone“书签到主屏幕"删除cookies和会话?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

现在我正在开发一个基于 Web 的应用程序,用户必须先登录.

Right now I am developing a Web-based Application, where the User has to login first.

当我通过 iPhone Safari 打开页面,登录并重新启动 Safari 时,我仍然登录(Cookie 和会话 ID 仍然设置).

When I open the Page by iPhone Safari, login and restart Safari, I am still logged in (Cookie & Session ID still set).

但是当我使用添加到主屏幕"添加此页面时,每次我单击该页面的图标时,我都必须再次登录.

But when I add this Page with "Add to Home Screen", each Time i click the Icon for that page, I have to login again.

我没有找到任何相关信息.我该怎么做才能让我的用户将此页面设置为他们的主屏幕作为图标,每次打开它时仍然不必登录?

I did not find any information about that. What can I do so my users can set this page to their home screen as icon and still don't have to login each time they open it?

推荐答案

有一个比 favo 更简单、更优雅的解决方案.

There is an easier and, imo, more elegant solution than favo's.

至少在 iOS 4.2.1、5.1.1、6.0 和 6.1 下(我无法测试其他版本),如果您手动延长会话 cookie 的生命周期,Safari 将保留会话 cookie 甚至允许在您的网络应用的安装主屏幕"版本与通过 Safari 本身进行的正常访问之间共享会话.

At least under iOS 4.2.1, 5.1.1, 6.0 and 6.1 (I couldn't test other versions), if you extend the lifetime of your session cookie manually, Safari will hold on to the session cookie and even allow sharing of the session between the 'home screen installed' version of your web app and normal visits through Safari itself.

诀窍是这样做:

// Start or resume session
session_start(); 

// Extend cookie life time by an amount of your liking
$cookieLifetime = 365 * 24 * 60 * 60; // A year in seconds
setcookie(session_name(),session_id(),time()+$cookieLifetime);

有关此策略的更详细讨论,您可以查看我对这个问题的回答:

For a more elaborate discussion of this strategy you can take a look at my answer of this question:

在 iPhone 上的 Web 应用程序中维护 PHP 会话

这篇关于iPhone“书签到主屏幕"删除cookies和会话?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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