123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- <?php
-
-
-
- include 'dbcleaner.php';
-
- function read_and_delete_first_line($filename) //This function will delete the first line of db.txt.
- {
- $file = file($filename);
- array_shift($file);
- file_put_contents($filename, $file);
- }
- date_default_timezone_set('America/Puerto_Rico');
- $decoded_location = json_decode(file_get_contents('php://input'));
-
-
- if(isset($decoded_location->latitude) && isset($decoded_location->longitude))
- {
- if(is_float($decoded_location->latitude) && is_float($decoded_location->longitude))
- {
- if(($decoded_location->latitude >= -90 && $decoded_location->latitude <= 90) && ($decoded_location->longitude >= -180 && $decoded_location->longitude <= 180))
- {
- if((($decoded_location->latitude >= 18.405912 && $decoded_location->latitude <= 18.407361) && ($decoded_location->longitude >= -66.050604 && $decoded_location->longitude <= -66.041167)) || (($decoded_location->latitude >= 18.403842 && $decoded_location->latitude <= 18.407778) && ($decoded_location->longitude >= -66.048252 && $decoded_location->longitude <= -66.046486)))
- {
- $decoded_location->inTime = date('h:i:s a',time());
- $encoded_location = json_encode($decoded_location);
- $file = 'db.txt';
- $totalLines = intval(exec("wc -l '$file'"));
-
- if($totalLines > 24)
- {
- read_and_delete_first_line($file);
- }
- $db = fopen("db.txt","a") or die("FAILED TO ACCESS DATABASE");
- fwrite($db,$encoded_location. "\n");
- fclose($db);
-
-
- }
- elseif((($decoded_location->latitude >= 18.402011 && $decoded_location->latitude <= 18.404062) && ($decoded_location->longitude <= -66.042888 && $decoded_location->longitude >= -66.051350)) || (($decoded_location->latitude >= 18.401272 && $decoded_location->latitude <= 18.404016) && ($decoded_location->longitude >= -66.050826 && $decoded_location->longitude <= -66.043554)))
- {
- $decoded_location->inTime = date('h:i:s a',time());
- $encoded_location = json_encode($decoded_location);
- $file = 'db2.txt';
- $totalLines = intval(exec("wc -l '$file'"));
- if($totalLines > 24)
- {
- read_and_delete_first_line($file);
- }
- $db = fopen("db2.txt","a") or die("FAILED TO ACCESS DATABASE");
- fwrite($db,$encoded_location. "\n");
- fclose($db);
- }
- }
- }
- }
- ?>
|