Forum Moderators: coopster

Message Too Old, No Replies

Need Help on LogFile

         

branmh

12:44 am on Oct 19, 2003 (gmt 0)

10+ Year Member



Need help with the LogFile, my query_string varible is not posting nothing in Function write_log, but in the Function write_logtracker it works. What is wrong with this?


<?
# First the DATE
$mon = date("m");
$mday = date("d");
$year = date("Y");
$date = date("Y-m-d¦G:i:s");

# change the directory path, silly!
$datapath = "/path/to/pagelogs/data/$mon";

# 0 if not used as a SSI - 1 if used as a SSI
$SSI = 1;

# mode = 0 = One file per day
# mode = 1 = a Single file always
$logmode = 1;

# Now with the show!
$filename = getenv('DOCUMENT_URI');
$document_name = preg_replace("/(\?.*)/", "", $filename);
$document_name = preg_replace("/[^\w]/", "_", $document_name);

#document_name = preg_replace("/\/[^\/]+\/(.*)\.php¦.html/i","$1", getenv('SCRIPT_NAME'));

if ($SSI == 1) {
$logfile = "$document_name";
write_log($datapath, $filename, $logmode, $date, $logfile);
exit;
}

if ($SSI == 0) {
write_logtracker($datapath, $filename, $logmode, $date, $logfile);
$redirect = getenv('QUERY_STRING');
header("Location: $redirect");
exit;
}

Function write_log($datapath, $filename, $logmode, $date, $logfile) {

global $HTTP_REMOTE_HOST, $HTTP_REMOTE_ADDR;
global $HTTP_REQUEST_METHOD, $HTTP_QUERY_STRING, $HTTP_USER_AGENT;
global $HTTP_REFERER;
$exists = 0;

if (is_dir($datapath)) {
if ($logmode) { $file = 'log' . $logfile.'.txt'; }
else { $file = 'log' . $logfile . '.' . date('Ymd') . '.txt'; }

$fname = "$datapath/$file";
if (file_exists($fname)) $exists = 1;

if ($file = fopen($fname, 'a')) {
$s = $date . '¦' . getenv('REMOTE_ADDR') . '¦' . getenv('REMOTE_HOST') . '¦' . getenv('HTTP_USER_AGENT') . '¦' . getenv('HTTP_REFERER') . '¦' . $filename . '?' . getenv('QUERY_STRING') . "\n";
fputs($file, $s);
fclose($file);
if (!$exists) chmod($fname, 0666);
}
}
}

Function write_logtracker($datapath, $filename, $logmode, $date, $logfile) {

global $HTTP_REMOTE_HOST, $HTTP_REMOTE_ADDR;
global $HTTP_REQUEST_METHOD, $HTTP_QUERY_STRING, $HTTP_USER_AGENT;
global $HTTP_REFERER;
$exists = 0;

if (is_dir($datapath)) {
if ($logmode) { $file = $logfile.'.txt'; }
else { $file = $logfile . '.' . date('Ymd') . '.txt'; }

$fname = "$datapath/$file";
if (file_exists($fname)) $exists = 1;

if ($file = fopen($fname, 'a')) {
$s = $date . '¦' . getenv('REMOTE_ADDR') . '¦' . getenv('REMOTE_HOST') . '¦' . getenv('HTTP_USER_AGENT') . '¦' . getenv('QUERY_STRING') . "\n";
fputs($file, $s);
fclose($file);
if (!$exists) chmod($fname, 0666);
}
}
}

?>

branmh

1:59 pm on Oct 19, 2003 (gmt 0)

10+ Year Member



It works, just the way I'm calling it in (SSI).