1234567891011121314151617181920212223 |
- <?php
- //Description: When activated this script will remove any old entries from db.txt.
-
- date_default_timezone_set('America/Puerto_Rico'); //Changes the default timezone of the script to Puerto Rico.
- $time = date("h:i:s",strtotime('-15 seconds')); //Stores the current time minus the a certain amount of time.
- $db = file('/var/www/html/db.txt'); //Access db.txt and stores each line into an array.
- $fsize = count($db); //Get the size of the db array.
- $change = False; //Boolian used to indicate if the file had to be changed.
- for($i = 0;$i < $fsize; $i++) //Loop that will iterate through the db array.
- {
- $decode = json_decode($db[$i]); //Gets the jsons stored in db and decodes them.
- if(date("h:i:s",strtotime($decode->inTime)) < date("h:i:s",strtotime($time))) //Compares if the inTime of stored in each json is less than the one in the time variable.
- {
- unset($db[$i]);//Removes the json in db[i].
- $change = True;//Indicates that their was change in db.
- }
- }
- if ($change == True)//Check if there was a change in db.
- {
- file_put_contents("/var/www/html/db.txt", $db);//Rewrites the db.txt with the contents of db.
- }
-
- ?>
|