Rate this script:  I Love it  /   I Hate it

Apache log anonymizer


Code


/**
* Takes Apache log file at $log_path, hashes the client address, and
* writes the file to $output_path. Useful for sharing log files without
* compromising user privacy. Reads input line-by-line to handle very
* large logs.
*
* @version 1.0
* @author Scott Reynen
* @copyright Scott Reynen 2006
* @link http://httpd.apache.org/docs/1.3/logs.html#accesslog
*/


$log_path = '';
$output_path = '';

$file = fopen( $log_path , 'r' );
$output = fopen( $output_path , 'a' );

while ( ! feof( $file ) )
{

        $line = fgets( $file , 8192 );
        $space = strpos( $line , ' ' );
        $out_line = md5( substr( $line , 0 , $space ) );
        $out_line.= substr( $line , $space );
        fwrite( $output , $out_line );

} // while

fclose( $file );
fclose( $output );
 

 

 
Apache log anonymizer scripts | Apache log anonymizer snippet | Apache log anonymizer example | Apache log anonymizer tutorial | Apache log anonymizer code