0 && !file_exists($VisitorsLoggingFileName)) { // Only if the directory opens correctly if (is_writeable($VisitorsLoggingDirectory) && ($DirectoryHandle = @opendir($VisitorsLoggingDirectory)) === true) { // Recurse through all files in this directory, but skip directories while ($file = readdir($DirectoryHandle) === true) if (!is_dir($file)) { // Retrieve last modification date, calculate age $FileFullPath = $VisitorsLoggingDirectory . '/' . $file; $FileStat = stat($FileFullPath); $FileAge = $TimeNow - $FileStat['mtime']; // Compare to config value: if older than allowed -- delete it // NOTE: this is potentially dangerous if you wanted to keep some other // files in the log directory -- they would get deleted as well if ($FileAge > ($VisitorsLoggingPurgeAfterDays * 86400)) unlink($FileFullPath); } closedir($DirectoryHandle); } } /* Task: Write Log Entry */ // Only if log file can be opened for appending // and the remote address is not on the ignore list if(($FileHandle = @fopen($VisitorsLoggingFileName, 'a')) !== false && !in_array($_SERVER['REMOTE_ADDR'], $VisitorsLoggingIgnoreList)) { // Variables available to VisitorLoggingFormat $ReplacementArray = array( '%Date' => strftime($VisitorsLoggingDateFormat, $TimeNow), '%Time' => strftime($VisitorsLoggingTimeFormat, $TimeNow), '%RemoteAddr:pad' => sprintf('%-15s', $_SERVER['REMOTE_ADDR']), '%RemoteAddr' => $_SERVER['REMOTE_ADDR'], '%Action:pad' => sprintf('%-8s', $action), '%Action' => $action, '%HttpHost' => $_SERVER['HTTP_HOST'], '%HttpReferer' => $_SERVER['HTTP_REFERER'], '%HttpUserAgent' => $_SERVER['HTTP_USER_AGENT'], '%WikiGroup' => FmtPageName('$Group', $pagename), '%WikiPage' => FmtPageName('$Name', $pagename), ); // Provide the resolved hostname only if it is needed // (resolving hostnames may be time-consuming) if (strstr($VisitorsLoggingFormat, '%RemoteHost')) { if(!empty($_SERVER['REMOTE_HOST'])) // This checks if you have "HostnameLookups (on|double)" in httpd.conf // most people don't as this is a resource hog $ReplacementArray['%RemoteHost'] = $_SERVER['REMOTE_HOST']; else $ReplacementArray['%RemoteHost'] = gethostbyaddr($_SERVER['REMOTE_ADDR']); } // Create the log entry $VisitorsLoggingEntry = $VisitorsLoggingFormat; foreach($ReplacementArray as $Variable => $Replacement) { $VisitorsLoggingEntry = str_replace($Variable, $Replacement, $VisitorsLoggingEntry); } // Write the log entry to file fwrite($FileHandle, $VisitorsLoggingEntry); // Close the log file fclose($FileHandle); } }