-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrequest.php
44 lines (38 loc) · 959 Bytes
/
request.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
<?php
session_start();
function getIfSet(&$value, $default = null) {
return isset($value) ? $value : $default;
}
if (!isset($_SESSION['count'])) {
$_SESSION['count'] = 0;
}
if (!isset($_SESSION['previous'])) {
$_SESSION['previous'] = ' ';
}
$_SESSION['count'] += 1;
$msg = getIfSet($_REQUEST['msg']);
if ($msg == null) {
$message = "(".$_SESSION['count']."): `msg` key missing from request";
$response = array (
'code' => 1,
'msg' => $message
);
$_SESSION['previous'] = $msg;
} else {
if (strcmp($_SESSION['previous'], $msg) == 0) {
$message = "(".$_SESSION['count']."): Duplicate received. Ignoring.";
$response = array (
'code' => 2,
'msg' => $message
);
} else {
$message = "(".$_SESSION['count']."): ".$msg;
$response = array (
'code' => 0,
'msg' => $message
);
$_SESSION['previous'] = $msg;
}
}
header('Content-type: application/json');
echo json_encode($response);