pkirsch Posted February 15, 2007 Share Posted February 15, 2007 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! Quote Link to comment Share on other sites More sharing options...
zq29 Posted February 15, 2007 Share Posted February 15, 2007 Which bit do you need help with? Writing the script, or creating the cron job? Quote Link to comment Share on other sites More sharing options...
pkirsch Posted February 15, 2007 Author Share Posted February 15, 2007 The script! Quote Link to comment Share on other sites More sharing options...
trq Posted February 15, 2007 Share Posted February 15, 2007 Post your code and the exact problem. Quote Link to comment Share on other sites More sharing options...
pkirsch Posted February 16, 2007 Author Share Posted February 16, 2007 I don't have a script yet! I'm wondering what you think would be the best solution! Quote Link to comment Share on other sites More sharing options...
corillo181 Posted February 16, 2007 Share Posted February 16, 2007 writting script is easy think of what you need and how you want it to work and write it in normal words.. like .. check account last login.. check current date.. and actions to take. Quote Link to comment Share on other sites More sharing options...
corbin Posted February 16, 2007 Share Posted February 16, 2007 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"); ?> Quote Link to comment Share on other sites More sharing options...
pkirsch Posted February 16, 2007 Author Share Posted February 16, 2007 Thank you very much! Any other suggestions? Ps how should i timestamp a login? Storing it in a mysql db? :) Quote Link to comment Share on other sites More sharing options...
Greaser9780 Posted February 16, 2007 Share Posted February 16, 2007 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.