Forum Moderators: coopster

Message Too Old, No Replies

PHP code to simulate apache log

anyone work out the code already?

         

amznVibe

6:28 am on Jan 7, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I have a bunch of domains parked on a single site for advertising.

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!

mack

6:42 am on Jan 7, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



Can you not use virtual hosts and have a different log for each domain?

Mack.

amznVibe

6:48 am on Jan 7, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I could but that slows me down from parking and removing domains at will. I don't even use my own nameservers, I just redirect with a cname forward.

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]

jatar_k

7:07 am on Jan 7, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



always depends on what you need

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.

amznVibe

7:35 am on Jan 7, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yup that's a nice simplified version. Thanks, all set, it's working well now.

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?

dcrombie

1:40 pm on Jan 7, 2004 (gmt 0)



NEVER chmod 777 - use chgrp <webserver user> and chmod g+w (or 775) on the directory instead!