-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstart_conn.php
63 lines (50 loc) · 1.82 KB
/
start_conn.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<?php
function GUID()
{
if (function_exists('com_create_guid') === true)
{
return trim(com_create_guid(), '{}');
}
return sprintf('%04X%04X-%04X-%04X-%04X-%04X%04X%04X', mt_rand(0, 65535), mt_rand(0, 65535), mt_rand(0, 65535), mt_rand(16384, 20479), mt_rand(32768, 49151), mt_rand(0, 65535), mt_rand(0, 65535), mt_rand(0, 65535));
}
$array = array("guid" => GUID(),"response"=>http_response_code());
// Connect to database
$host = 'localhost';
$user = 'root';
$pass = '';
$conn_error = 'Could Not Connect';
$dbname = "trackme";
// Create connection
$conn = mysqli_connect($host, $user, $pass, $dbname);
// Check connection
if ($conn) {
//On connection
$id_ = $array["guid"];
$user_name = mysqli_real_escape_string($conn,$_GET["user"]);
$lat_ = mysqli_real_escape_string($conn,$_GET["lat"]);
$long_= mysqli_real_escape_string($conn,$_GET["lng"]);
$channel_ = mysqli_real_escape_string($conn,$_GET["channel"]);
$query = "INSERT INTO users (id,username,channel,latitudes,longitudes,last_update) VALUES ('$id_' , '$user_name' , '$channel_' , $lat_ , $long_ , NOW())";
if (mysqli_query($conn, $query))
{
// 1 means successfully conected and the user can continue
$array['connection_status'] = '1';
}
else
{
//something unexpected happen
$array['connection_status'] = '2';
}
mysqli_close($conn);
} else{
//something unexpected happen
$array['connection_status'] = '2';
}
// output the results
if (isset($_GET["callback"])){
echo $_GET["callback"] . '(' . json_encode($array) . ')';
}
else{
echo json_encode($array);
}
?>