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
https://forums.phpfreaks.com/topic/38597-solved-member-delete-cron-job/
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");
?>

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.