Forum Moderators: open
AOL, which issues each user with a variety of IPs (is this still true?)
<?php
# Error Logging 2012-05-11
$oldSetting = ignore_user_abort( TRUE );// otherwise can screw-up logfile
if( !empty( $GLOBALS[ '_SERVER' ])) {
$_SERVER_ARRAY = '_SERVER';
} elseif( !empty( $GLOBALS[ 'HTTP_SERVER_VARS' ])) {
$_SERVER_ARRAY = 'HTTP_SERVER_VARS';
} else {
$_SERVER_ARRAY = 'GLOBALS';
}
//$requestHost = ${$_SERVER_ARRAY}[ 'HTTP_HOST' ];
$requestHost = ${$_SERVER_ARRAY}[ 'SERVER_NAME' ];
if(stristr($requestHost, 'example.co.uk')) {
if(stristr($strReqHost, 'dev')) {
define( '_DIRECTORY', '/var/www/vhosts/example.co.uk/dev/httpdocs/includes/logging/' );
} else if(stristr($strReqHost, 'www')) {
define( '_DIRECTORY', '/var/www/vhosts/example.co.uk/www/httpdocs/includes/logging/' );
}
}
define( '_LOGFILE','errorlogfile.txt' );
define( '_LOGMAXLINES','1000' );
global ${$_SERVER_ARRAY};
$logFile = _DIRECTORY . _LOGFILE;
$datetime = date( 'Y-m-d H:i:s O' );
$remoteIP = ${$_SERVER_ARRAY}[ 'REMOTE_ADDR' ];
$requestURI = ${$_SERVER_ARRAY}[ 'REQUEST_URI' ];
$userAgent = ( isset( ${$_SERVER_ARRAY}[ 'HTTP_USER_AGENT' ]))
? ${$_SERVER_ARRAY}[ 'HTTP_USER_AGENT' ]
: '<unknown user agent>';
$referer = ( isset( ${$_SERVER_ARRAY}[ 'HTTP_REFERER' ]))
? ${$_SERVER_ARRAY}[ 'HTTP_REFERER' ]
: '<unknown referer>';
$logLine = $datetime . " - " . $remoteIP . " - ". $requestHost . " - ". $requestURI . " - ". $userAgent . " - ". $referer . "\n";
$log = file( $logFile );// flock() disabled in some kernels (eg 2.4)
if( $fp = fopen( $logFile, 'a' )) {// tiny danger of 2 threads interfering; live with it
if( count( $log ) >= _LOGMAXLINES ) {// otherwise grows like Topsy
fclose( $fp );// fopen,fclose put close together as possible
while( count( $log ) >= _LOGMAXLINES ) array_shift( $log );
array_push( $log, $logLine );
$logLine= implode( '', $log );
$fp= fopen( $logFile, 'w' );
}
fputs( $fp, $logLine );
fclose( $fp );
}
exit();
ignore_user_abort( $oldSetting );
?>