I’m creating a web app to be used on iPad. An important feature is that a user can only log in once and on one device at a time. I’ve already achieved this by updating a field in our database from 0 to 1 if the user logs in.
However it is also important to have a timeout feature in case the user forgets to logout. I tried doing this in PHP but it wasn’t appropriate because the page would have to be refreshed before the script would run to log the user out.
So then I tried doing it client side with JavaScript (a simple page redirect after 30 minutes) but I’ve just learned that if you minimize Safari on the iPad all running scripts are halted so a user can easily click the home screen without logging out and the timeout wouldn’t work.
Sooo…I’m out of ideas…is there any way to timeout a person in Safari on the iPad?
Use your servers CRONJOB functionality http://en.wikipedia.org/wiki/Cron and write a script for DB wide logout checking. This way you would completely take the user client out of the question, all you would have to do is monitor users actions with a timestamps which you would later check with your script.
For example, if you’d have field in your user table
last_action_time, that you would update every time your site is reloaded or any other action is done. Just storetime()into that field. And for the cronjob script, just check all the users withlast_action_time< time()-(60*30) and update their field from 1 to 0 if that’s the case.