1

It's straight forward to add a web page as a web application. Find here a nice article.

The issue know is keeping a session open. Once switching to another app the session is closed and the user needs to re-enter his credentials.

I've found a similar entry without answer in stack-overflow.

Some hints ?

Community
  • 1
  • 1
ic3
  • 7,917
  • 14
  • 67
  • 115

2 Answers2

1

Instead of storing the login info in a $_SESSION variable, store it in a $_COOKIE. The cookie will be saved depending on when you set it to expire. As long as they log in "inside" the web app, or the regular web version (and the cookie is the same) they will not have to log in every time or when switching between the two.

adamdehaven
  • 5,890
  • 10
  • 61
  • 84
  • 3
    This answer needs to be removed! You should NEVER store login credentials within the $_COOKIE variable. This is a huge security risk, and there will be someone taking this person's advice! – leewilson86 Jun 04 '15 at 14:52
  • 1
    Not if the `$_COOKIE` is anonymous and isn't the actual login credential. – adamdehaven Jun 04 '15 at 14:56
0

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);

I tested this to work on iOS 4.2.1, 5.1.1, 6.0 and 6.1. The session is even restored after turning off and restarting the device.

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

Community
  • 1
  • 1
Wilbo Baggins
  • 2,701
  • 3
  • 26
  • 39
  • This works also on 7.0 and 7.1. There seems to be some bugs related to this. Sometimes the session doesn't restore. Deleting the icon, clearing history/cookies, does seem to help. However if you're signed in to the web app, then close, delete the icon, clear history, and adding the icon again, I'm signed in. So the cookie is stored somewhere else. – Niclas Apr 28 '14 at 14:55
  • 2
    Seriously - there's a reason why we set cookies to expire... this is not a solution – Tim Ogilvy May 03 '14 at 14:40
  • Hi Tim, you can still set cookies to expire, I don't see the problem. The question is specifically *aimed* at keeping the session alive; I can not possibly think of any other way to keep the session alive other than by extending the lifetime of the session cookie, since the entire existence of the session depends on the presence of that cookie. I'm really curious to hear what you think is a better solution. – Wilbo Baggins May 05 '14 at 17:53