iPhone “Bookmark to Homescreen” removes cookies and session?

后端 未结 4 2079
无人及你
无人及你 2020-11-28 06:55

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

When I open the Page by iPhone Safari, login and restart Safari, I am still log

4条回答
  •  忘掉有多难
    2020-11-28 07:42

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

    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.

    The trick is to do this:

    // 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:

    Maintain PHP Session in web app on iPhone

提交回复
热议问题