-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlogging.php
More file actions
55 lines (48 loc) · 1.47 KB
/
logging.php
File metadata and controls
55 lines (48 loc) · 1.47 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
<?
// Filename of log to use when none is given to write_log
define("DEFAULT_LOG","/home/filedraw/logs/social_" . date("Ymd", time() + 7200) . ".log");
/**
* write_log($message[, $logfile])
*
* Author(s): thanosb, ddonahue
* Date: May 11, 2008
*
* Writes the values of certain variables along with a message in a log file.
*
* Parameters:
* $message: Message to be logged
* $logfile: Path of log file to write to. Optional. Default is DEFAULT_LOG.
*
* Returns array:
* $result[status]: True on success, false on failure
* $result[message]: Error message
*/
function write_log($message, $logfile=DEFAULT_LOG) {
// 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 = date("Y-m-d H:i:s", $time + 7200);
// Append to the log file
if($fd = @fopen($logfile, "a")) {
$result = fputcsv($fd, array($date, $remote_addr, $request_uri, $message));
fclose($fd);
if($result > 0)
return array(status => true);
else
return array(status => false, message => 'Unable to write to '.$logfile.'!');
}
else {
return array(status => false, message => 'Unable to open log '.$logfile.'!');
}
}
?>