forked from benyafai/TinyAnalytics
-
Notifications
You must be signed in to change notification settings - Fork 0
/
req.php
35 lines (28 loc) · 1.16 KB
/
req.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
<?php
include 'config.php';
$org = str_replace(['http://www.', 'https://www.', 'http://', 'https://'], '', $_SERVER['HTTP_ORIGIN']);
$checkOrigin = strpos(join(' ', $ALLOWED_HTTP_ORIGINS), $org) !== false;
if (isset($_SERVER['HTTP_ORIGIN'])) {
// Decide if the origin in $_SERVER['HTTP_ORIGIN'] is one you want to allow
if ($checkOrigin)
header("Access-Control-Allow-Origin: {$_SERVER['HTTP_ORIGIN']}");
else
exit(0);
header('Access-Control-Allow-Credentials: true');
header('Access-Control-Max-Age: 86400'); // cache for 1 day
}
header('Access-Control-Allow-Methods: POST, OPTIONS');
// Access-Control headers are received during OPTIONS requests
if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS') {
if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']))
header("Access-Control-Allow-Headers: {$_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']}");
exit(0);
}
include 'tracker.php';
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$data = json_decode(file_get_contents('php://input'), true);
if ($checkOrigin && $data['sn']) {
record_visit($data['sn'], $data['ref']);
}
echo json_encode(['response' => 'ok']);
}