Over a million developers have joined DZone.

Apache Log Anonymizer

·

/**
* 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.

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

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

{{ parent.tldr }}

{{ parent.urlSource.name }}