PDA

View Full Version : Remove user account after 30 days


zoliky
07-06-06, 05:29 AM
I have a PHP script to add users in database.
Every user has an activation code. A random generated sha1 hash.

This is my table:


--------------------------------------------------------------------
user_id | username | password | email | activate
1 zoliky somepass an_email hsdjf7345h3476hgdjf6g7d
2 user2 somepass an_email hjghjdfhgjdfhgjdfhjghdfjhg


Every user receive an e-mail to activate the account.
When user "zoliky" activate the account the table is modified:


--------------------------------------------------------------------
user_id | username | password | email | activate
1 zoliky somepass an_email 0
2 user2 somepass an_email hjghjdfhgjdfhgjdfhjghdfjhg


I want to delete user which not activate the account for 30 days.
Any idea, what need to do ?

I need a little example code.

Thanks !

Nico
07-06-06, 06:32 AM
Moved to database.


You could add a new filed to the table, and store the timestamp when a new user registers. Then via cron job could you remove all old and unconfirmed entries every day.


$checktime = 3600*24*30;

mysql_query("DELETE FROM table WHERE registration_time < '". (time() - $checkdate) ."' AND activate != 0");


Something like this should do it.

zoliky
07-06-06, 06:50 AM
$checkdate is not $checktime ?

What I need to do when I want to delete inactive accounts every 10 minutes ? only for testing purposes.

I need to write:

$checkdate = 10; ?

Thank you very much !