-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlog.php
40 lines (34 loc) · 1008 Bytes
/
log.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
<?php
//call log_it along with the necessary 'message' to be written in log file
function log_it($message)
{
$config = parse_ini_file('config.php');
$logfile = $config['logfile'];
// Get time of request
if( ($time = $_SERVER['REQUEST_TIME']) == '') {
$time = time();
}
// Get IP address
if( ($remote_addr = $_SERVER['REMOTE_ADDR']) == '') {
$remote_addr = "REMOTE_ADDR_UNKNOWN";
}
// Get requested script
if( ($request_uri = $_SERVER['REQUEST_URI']) == '') {
$request_uri = "REQUEST_URI_UNKNOWN";
}
// Format the date and time
date_default_timezone_set('America/New_York');
$date = date("Y-m-d H:i:s", $time);
// Append to the log file
if(file_exists($logfile))
{
$writelog = fopen($logfile, "a");
$logdata = fputcsv($writelog, array($date, $remote_addr, $request_uri, $message));
fclose($writelog);
}
}
//Test if log.php is working or not
//$test = log_it("test logger");
//output format
//"2016-10-31 23:16:09",::1,/log.php,"test logger"
?>