Exforsys
+ Reply to Thread
Results 1 to 6 of 6

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

  1. #1
    Charith is offline Junior Member Array
    Join Date
    Jan 2006
    Answers
    11

    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


  2. #2
    Rahulbatra is offline Senior Member Array
    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);
    ?>


  3. #3
    rachelle is offline Member Array
    Join Date
    Apr 2006
    Answers
    97
    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.


  4. #4
    cyrus is offline Senior Member Array
    Join Date
    Apr 2006
    Answers
    128
    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.


  5. #5
    caradoc is offline Senior Member Array
    Join Date
    Apr 2006
    Answers
    122
    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.


  6. #6
    sammy is offline Senior Member Array
    Join Date
    Apr 2006
    Answers
    144
    You can use the option crontab -e for running or executing the cron job from command line in your Linux/Unix systems.


    •    Sponsored Ads



Latest Article

Network Security Risk Assessment and Measurement

Read More...