-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlogger.php
More file actions
102 lines (84 loc) · 2.3 KB
/
logger.php
File metadata and controls
102 lines (84 loc) · 2.3 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
<?php
// ini_set('display_errors', 1);
// ini_set('display_startup_errors', 1);
// error_reporting(E_ALL);
session_start();
if (!file_exists('logs')) {
mkdir('logs', 0777, true);
}
$pid = isset($_SESSION["playerid"]) ? filter_var($_SESSION["playerid"], FILTER_VALIDATE_INT) : "-";
$gid = filter_var($_SESSION['gameid'], FILTER_VALIDATE_INT);
$hgid = filter_var($_SESSION['hostedgameid'], FILTER_VALIDATE_INT);
$pre = "[".$pid."|".$gid."|".$hgid."] : ";
$logfilename = "logs/ascard_logfile";
$logfileext = ".txt";
$log_access = true;
// roll over
function rollover() {
// roll over logfile after 5 mb is reached
global $logfilename;
global $logfileext;
$checkname = $logfilename.$logfileext;
$checkname1 = $logfilename."_1".$logfileext;
$checkname2 = $logfilename."_2".$logfileext;
$checkname3 = $logfilename."_3".$logfileext;
$checkname4 = $logfilename."_4".$logfileext;
$size = filesize($logfilename.$logfileext);
if ($size > 5242880) { // is the current logfile bigger than 5 mb
if (file_exists($checkname4)) {
// delete #4 if it exists
unlink($checkname4);
}
if (file_exists($checkname3)) {
// rename #3 to #4 if it exists
rename($checkname3, $checkname4);
}
if (file_exists($checkname2)) {
// rename #2 to #3 if it exists
rename($checkname2, $checkname3);
}
if (file_exists($checkname1)) {
// rename #1 to #2 if it exists
rename($checkname1, $checkname2);
}
if (file_exists($checkname)) {
// rename current file to #1 if it exists
rename($checkname, $checkname1);
}
}
}
// write a line to log
function logMsg($msg) {
global $pre;
rollover();
$logfile = fopen($logfilename.$logfileext, "a");
fputs($logfile,
$pre.
date("d.m.Y, H:i:s", time()).
" ".
$msg."\n"
);
fclose($logfile);
}
// log the access to a file
if ($log_access) {
rollover();
$logfile = fopen($logfilename.$logfileext, "a");
if(isset($_SERVER['HTTP_REFERER'])) {
$ref = $_SERVER['HTTP_REFERER'];
} else {
$ref = "no referer";
}
$refererStr = ", ".$_SERVER['REMOTE_ADDR'].
", ".$_SERVER['REQUEST_METHOD'].
", ".$_SERVER['PHP_SELF'].
", ".$_SERVER['HTTP_USER_AGENT'].
", ".$ref."\n";
fputs($logfile,
$pre.
date("d.m.Y, H:i:s", time()).
$refererStr
);
fclose($logfile);
}
?>