tags:

views:

49

answers:

3

I need to delete old user datas in the DB, if user session is timeout.

How can I solve this problem with using PHP?

+1  A: 

You can store the session_key with the rows in the database, and then define a time limit yourself. And then create a cronjob that delete's all rows with session_key's that has not been used within your limit.

A default session last until the browser is closed, so you cant know how many seconds that the session is active. Even when the session is closed, the session will not be deleted until the garbage collector removes it.

madsleejensen
A: 

There is no way to add code to run when the session times out. You'll have to come up with a scheme yourself. I'd suggest adding a timestamp to your database records and updating it every time the data is accessed. Then have a script via cron go through the records and delete those that are older than the session timeout.

Manos Dilaverakis
+1  A: 

You can set the time for session time out . say 30 mins.

sesssion_gc_maxlifetime

You can check the login time of a user .

But if you want to delete the data , better to keep session in DB or at least

keep a status , login or logout and login time and logout time in the DB

It will be safe

So you can delete the data based on login time and current timedifference

set a cron job run in 30 mins or whatever time you wish

zod