|
@@ -0,0 +1,40 @@
|
|
1
|
+<?php
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+ include 'dbcleaner.php';
|
|
6
|
+
|
|
7
|
+ function read_and_delete_first_line($filename) //This function will delete the first line of db.txt.
|
|
8
|
+ {
|
|
9
|
+ $file = file($filename);
|
|
10
|
+ array_shift($file);
|
|
11
|
+ file_put_contents($filename, $file);
|
|
12
|
+ }
|
|
13
|
+ date_default_timezone_set('America/Puerto_Rico');
|
|
14
|
+ $decoded_location = json_decode(file_get_contents('php://input'));
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+ if(isset($decoded_location->latitude) && isset($decoded_location->longitude))
|
|
18
|
+ {
|
|
19
|
+ if(is_float($decoded_location->latitude) && is_float($decoded_location->longitude))
|
|
20
|
+ {
|
|
21
|
+ if(($decoded_location->latitude >= -90 && $decoded_location->latitude <= 90) && ($decoded_location->longitude >= -180 && $decoded_location->longitude <= 180))
|
|
22
|
+ {
|
|
23
|
+ $decoded_location->inTime = date('h:i:s a',time());
|
|
24
|
+ $encoded_location = json_encode($decoded_location);
|
|
25
|
+ $file = 'db.txt';
|
|
26
|
+ $totalLines = intval(exec("wc -l '$file'"));
|
|
27
|
+
|
|
28
|
+ if($totalLines > 24)
|
|
29
|
+ {
|
|
30
|
+ read_and_delete_first_line($file);
|
|
31
|
+ }
|
|
32
|
+ $db = fopen("db.txt","a") or die("FAILED TO ACCESS DATABASE");
|
|
33
|
+ fwrite($db,$encoded_location. "\n");
|
|
34
|
+ fclose($db);
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+ }
|
|
38
|
+ }
|
|
39
|
+ }
|
|
40
|
+?>
|