Hi ...

I am a total php newbie.

As clients move about my site they may cause entries in a temporary sql table that includes a field for their session id. If they leave the site by logging out properly, the rows in the table associated with their session are deleted. However, if they simply abandon the site, the table isn't purged.

I would like to be able to clean up the table regularly using a cron, but I don't know how to identify which sessions listed in the table are live, and which are older abandoned sessions. I'm worried about deleting data in live sessions.

Any ideas please .....

Member Avatar for diafol

Add a field called last_impression to your table. This is updated with a unix time every time an user goes to a new page. Cron -> logout all users where now() - last_impression > than a certain number (seconds, e.g. 3600 for 1 hour).

An user still on your site but hasn't done anything for 1 whole hour will just need to log in again.

Thanks ardav ...

I get the idea ... if the time since any activity is above my threshold ... wham!

Bewdy ... should fix it :)

G-fer.

Member Avatar for diafol

Should have mentioned - perhaps it's obvious - the DB will need to be updated on every page impression - so it's not a freebie - there is an overhead:

Pseudocode:
if login session exists -> update the user record in the table on entering each page

Mmm ..

I guess I could simply update the session_id each time.

G-fer

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.