-
Notifications
You must be signed in to change notification settings - Fork 0
/
token.php
38 lines (25 loc) · 768 Bytes
/
token.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
<?php
header('Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept');
$token = $_POST['token'];
require_once "Database.php";
$conn = new Database("./data/devices.json");
$devices = $conn->get_all_records();
function check_if_token_exists($devices,$token){
if(empty($devices)){
return false;
}
foreach ($devices as $device) {
if ($device['token'] == $token) {
return true;
}
}
return false;
}
if(!check_if_token_exists($devices,$token)){
$conn->insert(['token'=> $token]);
}
$data = array(
'error' => $token,
);
//header('Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept');
echo json_encode($data,true);