forked from rbwatson/wlux_test_server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
logger.php
executable file
·50 lines (41 loc) · 1.3 KB
/
logger.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
45
46
47
48
49
<?php
include 'config_files.php';
// Logs page transitions on a weblabux study site.
// In the final implementation, this will obviously write data to
// a database instead of a text file.
//$type = $_POST["type"]; // the type of action we're logging
//$data_arr = array();
$condition = -1;
$json = $_POST["data"];
$session = $json["wlux_session"];
// get the condition from the sessions.txt (eventually get it from a db given
// the session id)
$file = fopen($sessionDataFile,"r");
while(! feof($file)) {
$line = fgets($file);
$line = explode(' ', $line);
if ($line[0] == $session) {
$condition = $line[1];
}
}
fclose($file);
if ($condition != -1 && !empty($session) && !empty($json)) {
$data = "log_entry_time:\t".date('c')."\n";
while (list($key, $value) = each($json)) {
$data = $data . "\t". $key . ":\t" . $value . "\n";
}
$data = $data . "\n";
$file = $sessionLogFolder . "session" . $session . ".txt";
$fileResult = file_put_contents($file, $data, FILE_APPEND);
// send success response
if (!headers_sent()) {
header('X-PHP-Response-Code: 200', true, 200);
}
} else {
// send error response
if (!headers_sent()) {
header('X-PHP-Response-Code: 500', true, 500);
}
}
// otherwise we got an invalid request - just don't write anything to the file
?>