Jump to content

[SOLVED] Delete user after 72 hours


studgate

Recommended Posts

Hi Guys,

I am trying to automatically deleting users that have not activated their account

after 72 hours. How can I go about doing that?? There are two fields in the database

that I want to to check: if active (int) = 0 (not active) or 1 (active) and compare the

date_registered(timestamp) with 72 hours.

 

Any ideas are welcome, thanks in advance guys.

Link to comment
Share on other sites

Easiest way way be to execute a cron job every hour, something like....

 

0 * * * * /usr/bin/mysql -uYOURUSERNAME -pYOURPASSWORD YOURDATABASE -e 'DELETE FROM tbl WHERE date_registered < DATE_SUB(NOW(), INTERVAL 72 HOURS);';

Link to comment
Share on other sites

I was thinking about a function that runs on all pages and in the backend...

it will connect to the database, check if status = 0 and date_registered is > 72 hours.

if both conditions are met, delete the user.

 

 

No point running an extra query on every page if you don't need to but yeah... if you don't have access to cron I guess thats an option.

 

ps: I forgot the status check in my query.

 

0 * * * * /usr/bin/mysql -uYOURUSERNAME -pYOURPASSWORD YOURDATABASE -e 'DELETE FROM tbl WHERE status = 0 && date_registered < DATE_SUB(NOW(), INTERVAL 72 HOURS);';

Link to comment
Share on other sites

Thanks Thorpe, there was one mistake in your query, 72 HOUR not 72 HOURS/

 

Okay I create a function that will do that for me in the backend or any page that you want.

 

Here it is for all who needs something like this.

 

function DeleteInactiveUsers(){
$sql = 'DELETE FROM users_table WHERE status = 0 && registered_date < DATE_SUB(NOW(), INTERVAL 72 HOUR);';
mysql_query($sql) or die('The MySQL query failed. MySQL said: '.mysql_error());
}

 

You can just call this on the page that you want:

<? DeleteInactiveUsers(); ?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.