-
Notifications
You must be signed in to change notification settings - Fork 3
/
track.php
36 lines (31 loc) · 940 Bytes
/
track.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
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
$actions = array(
'human' => 'human_access.log',
'interested' => 'interested_access.log',
'use' => 'use_access.log',
);
$data = file_get_contents('php://input');
$data = json_decode($data, true);
if (!isset($data['action']) && !in_array($data['action'], $actions)) {
header('Status: 400');
die('Needs an action');
} elseif (!isset($data['screen'], $data['uri'], $data['referrer'])) {
header('Status: 400');
die('Missing data');
}
$file = 'logs/' . $actions[$data['action']];
$fh = fopen($file, 'a');
fwrite($fh, implode("\t", array(
date('Y-m-d H:i:s'),
$data['screen'],
$data['uri'],
isset($_SERVER['HTTP_DNT']) ? 'DNT' : $_SERVER['REMOTE_ADDR'],
isset($_GET['ua']) ? $_GET['ua'] : $_SERVER['HTTP_USER_AGENT'],
$data['referrer'],
isset($data['state']) ? $data['state'] : '',
isset($data['random']) ? $data['random'] : '',
)));
fwrite($fh, "\n");
fclose($fh);