18

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?

KPM
  • 10,558
  • 3
  • 45
  • 66
nikstep
  • 465
  • 1
  • 4
  • 8

1 Answers1

24

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:

$lifetime = 31536000; // one year 
setcookie($varName,$varValue,time()+$lifetime); 

If you're using PHP sessions, you will have to rewrite the cookie to add a lifetime greater than 0:

setcookie(session_name(),session_id(),time()+$lifetime);

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.

KPM
  • 10,558
  • 3
  • 45
  • 66
  • Wow, thank you so much!! I've been researching this for several days now! I even tried saving the session ID in local storage and sending it back to the server when the app launched again, but that didn't work. Thanks again! – Kevin Jantzer Jan 08 '13 at 06:47
  • @KPM but don't you think it's causes serious security issues? – nKognito Apr 28 '13 at 13:33
  • 1
    You don't need to set the expire to a year if you're worried about security - set it only as long as your user needs - aka - a bit more than the average time between use. We use it so when users make calls or texts and close the webapp they can bounce back into it and not have to log in...but if its closed for an hr for example, they need to log in. – Ross Apr 15 '14 at 21:05