
- Forum
- Programming Talk
- PHP
- Session cleanup Cron Job
Session cleanup Cron Job
This is a discussion on Session cleanup Cron Job within the PHP forums, part of the Programming Talk category; Hi I want to know how to write a cron job to delete inactive sessions on the server, Kindly help ...
-
Session cleanup Cron Job
Hi
I want to know how to write a cron job to delete inactive sessions on the server, Kindly help me.
Charith
-
04-14-2007, 03:04 AM #2
- Join Date
- Apr 2006
- Answers
- 124
You can use the below for deletion of inactive users.
#!/usr/bin/php -q
<?php
// cron job to delete inactive users older than 48 hours
$db=mysql_connect('server','user','password');
mysql_select_db('your_phpbb_database_here',$db);
$strSQL="DELETE FROM phpbb_users WHERE user_active=0 AND " .
"user_id>0 AND FROM_UNIXTIME(user_regdate)<" .
"DATE_SUB(NOW(),INTERVAL 2 DAY);";
mysql_query($strSQL,$db) or die(mysql_error());
mysql_close($db);
?>
-
Charith use the above hint given by our friend above and Make sure that the /usr/bin/php points to the location of PHP on your system, and replace the MySQL server name, user, and password with yours.
-
The above gives a script and one must get it executed daily to remove the inactive users which can be done by using a cron job.
-
How can I execute the cron job from my command line in my Linux/Unix systems. In other words I want to know the option for executing the cron job from my command line in my Linux/Unix systems.
-
You can use the option crontab -e for running or executing the cron job from command line in your Linux/Unix systems.
-
Sponsored Ads

Reply With Quote





