|
Posted by Erwin Moller on 09/26/05 11:51
Mikel Astiz wrote:
> Hi,
>
> I am looking for a simple way to detect session ends so I can update a
> session table. I am new to PHP and don't understand how such event can be
> handled, since there seems not to be a corresponding overridable function.
> I've found 'register_shutdown_function', but apparently it detects
> connection breaks while the page is being loaded (I'm not sure though).
>
> I supose it will always be possible to control timeouted sessions by
> polling, but I wouldn't like to do so. Of course, client side scripts are
> not enough. I want to handle broken connections and prevent from evil
> users too.
>
> Any ideas will be welcome, and please correct me if I said something
> senseless.
>
> Thanks,
> Mikel
If you are using a database to store your sessions, also store in the same
row a field named 'lastupdated'.
Now delete all rows that are not updated for X minutes, where X is something
you think makes sense. (30 minutes eg)
When to run that housekeepingcode?
Why not do it like php does it with file-stored sessions?
Just run it once every 100 times on avarage.
(You can use a random number to decide if you need cleaning.)
Just my 2 cents.
Regards,
Erwin Moller
[Back to original message]
|