DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Apache Log Anonymizer

04.11.2006
| 6956 views |
  • submit to reddit
        
/**
* 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 );