-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreadExit.php
More file actions
47 lines (41 loc) · 1.72 KB
/
readExit.php
File metadata and controls
47 lines (41 loc) · 1.72 KB
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
<?php
require_once 'config.php';
require_once 'em4100Decode.php';
// вход :'1001'
// изход:'1002'
// $stamp = YYYYMMDDHHMMSS
$fp = fopen(EXIT_PORT, 'r');
$rfid = '';
while (true) {
$ch = fread($fp, 1);
if ($ch != '?') {
$rfid .= $ch;
} else {
$card = decode($rfid);
// Изпращаме картата
$search = array('{card}','{stamp}');
$stamp = date("YmdHis");
$replace = array($card, $stamp);
$exitUrl = str_replace($search,$replace,EXIT_URL);
$res = @file_get_contents($exitUrl);
if (FALSE === $res) {
// Неработещо УРЛ
file_put_contents('debug.log', date("Y-m-d H:i:s") . " " . basename(__FILE__). " " . " - {$card} - Неработещо УРЛ \n", FILE_APPEND);
file_put_contents('noSended.log', "exit|{$card}|{$stamp}\n", FILE_APPEND);
continue;
}
if (strpos($res,'inserted')!==FALSE) {
// Въведен запис в BGERpa
file_put_contents('debug.log', date("Y-m-d H:i:s") . " " . basename(__FILE__). " " ." - $card - $stamp - Въведен запис в BGERpa \n", FILE_APPEND);
} else {
// Warning
file_put_contents('debug.log', date("Y-m-d H:i:s") . " " . basename(__FILE__). " ". $exitUrl ." - $card - $stamp - Неполучено потвърждение от сървъра \n", FILE_APPEND);
file_put_contents('noSended.log', "exit|{$card}|{$stamp}\n", FILE_APPEND);
}
$rfid = '';
// рестартираме порта
fclose($fp);
usleep(100000); // 0.1 sec
$fp = fopen(EXIT_PORT, 'r');
}
}