Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iPhone "Bookmark to Homescreen" removes cookies and session?

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 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?

like image 905
christian Muller Avatar asked Sep 28 '10 14:09

christian Muller


People also ask

What is a bookmark on iPhone home screen?

In the Safari app , you can bookmark websites, add websites to Favorites, or add a website icon to the Home Screen to easily revisit later.

How do I change the bookmarks on my iPhone home screen?

Open the bookmarks menu by tapping the open book icon. Tap the Bookmarks tab and then tap Edit. Create a new folder, or delete, rename, or reorder your bookmarks. When you've completed whatever changes you want to make, tap Done.


2 Answers

A really simple approach could be to use a unique token in your Bookmark-URL which can serve you as a unique device identifier.

Example: http://myWebApp.com/?token=randomId29238/1

The token can be generated at the server side at opening time of the application in Mobile Safari and before the user is prompted with the "Add to Home Screen" information. The token can then be added to the URL using a quick redirect (…&token=randomToken) or a location hash (…#randomToken).

Whenever the Bookmark is now opened from the Home Screen, the token is sent to your server and you can identify the user's active session. You may also use the token as a permanent session id, but I advise against that because of security concerns.

To allow future logout and login procedures, you can always assign the new sessions to the token.

The token will serve you as a unique device identifier whenever the user will re-open your link from his Home Screen.

like image 97
favo Avatar answered Sep 19 '22 20:09

favo


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

like image 21
Wilbo Baggins Avatar answered Sep 20 '22 20:09

Wilbo Baggins