Repositorio del curso CCOM4030 el semestre B91 del proyecto Trolley

dbcleaner.php 1.1KB

1234567891011121314151617181920212223
  1. <?php
  2. //Description: When activated this script will remove any old entries from db.txt.
  3. date_default_timezone_set('America/Puerto_Rico'); //Changes the default timezone of the script to Puerto Rico.
  4. $time = date("h:i:s",strtotime('-15 seconds')); //Stores the current time minus the a certain amount of time.
  5. $db = file('/var/www/html/db.txt'); //Access db.txt and stores each line into an array.
  6. $fsize = count($db); //Get the size of the db array.
  7. $change = False; //Boolian used to indicate if the file had to be changed.
  8. for($i = 0;$i < $fsize; $i++) //Loop that will iterate through the db array.
  9. {
  10. $decode = json_decode($db[$i]); //Gets the jsons stored in db and decodes them.
  11. 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.
  12. {
  13. unset($db[$i]);//Removes the json in db[i].
  14. $change = True;//Indicates that their was change in db.
  15. }
  16. }
  17. if ($change == True)//Check if there was a change in db.
  18. {
  19. file_put_contents("/var/www/html/db.txt", $db);//Rewrites the db.txt with the contents of db.
  20. }
  21. ?>