4

log

write_log
SYNOPSIS

write_log($logfile, $textline=false)

DESCRIPTION
CODE
  1. require_once 'clientipaddress.php';
  2. require_once 'validateipaddress.php';
  3.  
  4. function write_log($logfile, $textline=false) {
  5.     global $log_dir;
  6.  
  7.     $ipaddress = client_ip_address();
  8.  
  9.     if (!validate_ip_address($ipaddress)) {
  10.         return false;
  11.     }
  12.  
  13.     $timestamp=strftime('%Y-%m-%d %H:%M:%S', time());
  14.  
  15.     $logmsg="$timestamp $ipaddress";
  16.     if ($textline) {
  17.         $logmsg .= "\t$textline";
  18.     }
  19.     $logmsg.="\n";
  20.  
  21.     $file = isset($log_dir) ? ($log_dir . DIRECTORY_SEPARATOR . $logfile) : $logfile;
  22.  
  23.     $r = @file_put_contents($file, $logmsg, FILE_APPEND);
  24.  
  25.     return $r;
  26. }
SEE ALSO

track, clientipaddress, validateipaddress

Comments

To add a comment, click here.