Jump to content

[SOLVED] Member Delete Cron Job!


pkirsch

Recommended Posts

Hello,

 

I am trying to make a .php file that will check when the last time the members of my website logged into their account, and if it finds that they have NOT logged in for more then six months, it will delete their account!

 

The accounts consist of files and MySQL Databases!

This will run as a cron job every two days!

Link to comment
Share on other sites

If the last login time is store as a time stamp it's like crazy easy....

 

Just something like

 

<?php
//some how make sure the correct place is requesting the page (cron job)
//db connection stuff (I'm assuming MySQL)
$max_inactive = (60*60*24)*180; //(seconds in one day)*180 days
$max_inactive = time() - $max_inactive;
$q = mysql_query("DELETE * FROM `users` WHERE last_login < $max_inactive");
?>

Link to comment
Share on other sites

When your user logs in it gets checked by a file like checkuser.php. Add to that file a mysql query that will update the last_login portion of your table.

$sql="UPDATE `users` SET `last_login`= now() WHERE `username` = $_POST['username']"

$result=mysql_query($sql) or die(mysql_error());

 

 

Of course Corbin and my suggestions will only work if you have a field in your table for last_login. Also where I put `users` you must put in the name of your table. If you place both of our codes in your file that checks the users posted information it will update each users last login as well as delete an inactive user everytime someone logs in.

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.