Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Apache Log Anonymizer

DZone's Guide to

Apache Log Anonymizer

·
Free Resource

/**
* 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 );
Topics:

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}