Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail From: Arno Welzel Newsgroups: comp.lang.php Subject: Re: session handler auto log out Date: Mon, 21 Nov 2011 16:06:00 +0100 Organization: A noiseless patient Spider Lines: 40 Message-ID: <4ECA68D8.8070001@arnowelzel.de> References: <11984037.1120.1321742991368.JavaMail.geo-discussion-forums@prlm15> <4ECA5B14.5020200@arnowelzel.de> <4eca634f$0$6990$e4fe514c@news2.news.xs4all.nl> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Injection-Info: mx04.eternal-september.org; posting-host="dd4uQGf4fHOQcq7/hg1u1Q"; logging-data="21197"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18/htuLpB+enxFi1/fJZEfbFiI3Gwdy96g=" User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:8.0) Gecko/20111105 Thunderbird/8.0 In-Reply-To: <4eca634f$0$6990$e4fe514c@news2.news.xs4all.nl> Cancel-Lock: sha1:0MPabIMSYKE35kt9tpy1TYWalT8= Xref: x330-a1.tempe.blueboxinc.net comp.lang.php:3843 Erwin Moller, 2011-11-21 15:41: > On 11/21/2011 3:07 PM, Arno Welzel wrote: >> DavidB, 2011-11-19 23:49: >> >>> Is there a way to model a session handler to auto logout after a specified >>> period of time without refreshing the page? Something similar to a bank >>> website that auto logs me out and redirects me to another page. >> >> If you want to force the client to redirect the user to another page as >> soon as the session on the *server* times out you must do periodically >> checks on the client e.g. using AJAX. >> >> > > Hi Arno, > > That approach could bite you in the back. > For example: If your session timeout is 30 minutes, and you check each > 10 minutes via AJAX, you'll never log out because the AJAX request > "resets" the time-out to a new 30 minutes. Of course i assumed that the AJAX request will not reset the session timeout (and yes, i know how sessions work in PHP). > This can all be circumvented (if you know how Sessions work in PHP), but > I would advise the OP to follow Denis's advice and simply use a > window.setTimeout() in JavaScript. Much easier. I agree - setTimeout() is the easies solution in most cases. But you have to take care that any further interaction will immediatly cancel the timeout. Depending on the structure of the site and how interaction is done (e.g. using AJAX and not complete reloads of the page), a simple setTimeout() may not be enough. -- Arno Welzel http://arnowelzel.de http://de-rec-fahrrad.de