Forum Moderators: coopster
Recently I realized I am unable to track true traffic based on each domain name because apache writes the log as if it's all on the same domain, ugh.
This could be cured easily with PHP automagically writing a seperate log based on the host name it sees coming in.
I'd like to write the logs in true apache format so I can analyze them with various tools.
Has anyone worked out the code to do that and willing to share before I spend an hour figuring it out?
Thanks for any help!
The single page I have in place I wrote myself and it's dynamic, switching based on domain name so it's very low hassle.
After a bit of "Google dumpster diving (tm)" ;) I found this, which saved me that hour:
vsbabu.org/mt/archives/2002/08/24/quick_script_to_log_site_hits.html
[edited by: jatar_k at 7:03 am (utc) on Jan. 7, 2004]
[edit reason] delinked [/edit]
I use this on one site
<?
$fp = @fopen("track.log","a");
$today = getdate();
$now = $today['year'] . "/" . $today['mon'] . "/" . $today['mday'] . " " . $today['hours'] . ":" . $today['minutes'] . ":" . $today['seconds'];
$string = "ip:" . $_SERVER['REMOTE_ADDR'] . " -ref:" . $_SERVER['HTTP_REFERER'] . " -agent:" . $_SERVER['HTTP_USER_AGENT'] . " - " . $now . "\n";
@fwrite($fp,$string);
@fclose($fp);
?>
you could do the open based on $_SERVER['HTTP_HOST'] giving you different logs.
A note for people in the future trying this, don't forget to chmod 777 the directory you are trying to write the logs to or you might get access errors.
I wish I could stuff screensize & javascript on/off into the log but that would void the apache log format, oh well. How do some analyzers deal with the added gzip compression data some people collect? Can you maybe append stuff at the end of the line and not break programs?