Re: Trigger an action on session timeout - feature request?
| From: | Philip Thompson | Date: | Tue, 13 Nov 2007 15:15:41 +0000 |
| Subject: | Re: Trigger an action on session timeout - feature request? | ||
| References: | 1 2 3 4 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-264440@lists.php.net to get a copy of this message | ||
On Nov 12, 2007 3:19 PM, Jake <linux@nittanytravel.com> wrote:
> >> Is there any possibility to trigger an action when the session is
> >> inactive
> >> for some time? I need to log users' login and logout, and so I need to
> >> know
> >> about logouts caused by timeout. Neither there seems to be a
> possibility
> >> of a workaround like walking through all my sessions for timeouted ones
> >> and destroy them myself.
>
> if you want it server side, it would have to be some kind of scheduled job
> (cron, etc). Most banks have session timeouts using javascript or asp,
> client side. You do this with php by putting the session timeout duration
> into javascript, then a settimeout and if browser closed... etc.. the
> default in php.ini is 24 minutes... u can use this, or use any value......
> then have logout.php clean up
>
> <?php
>
> $timeout = ini_get('session.gc_maxlifetime') * 1000 // convert from
> seconds
> to milliseconds for javascript;
>
> ?>
>
> <html>
> <head>
> <script type="text/javascript">
> <!--
> setTimeout("window.location = 'logout.php'",<?php echo $timeout?>);
> // -->
> </script>
> </head>
> <body>
>
> </body>
> </html>
To add onto this... you may want to update the timeout each time the user
takes an action (onclick, onmousemove, etc). This way, if a user is reading
a long contract on his bank statement (for example), then it won't
automatically close the page - quite frustrating! =D
~Philip