a self-made log statistics with wordpress

It’s not the case of freeshell.de or nic-nac-project.de that kindly is hosting this blog, but in the world there are some low cost hosting profiles where You can’t access your weblog.
Several times the webserver logs nothing at all.
Since I think  it’s a nice thing to have my web access statistics, if Your wordpress blog is on such kind of webserver, I suggest to add some plugin to your wordpress installation, such as myStat.

Once I preferred to write my own the http access log, in order to process it with awstats.
To do this, I changed the footer.php of my wordpress theme adding theese lines after the </html> tag:

<?php wp_footer(); ?>
</body>
</html>
<?php
// kludge to write a sort of access log on a file….
$monthyear = date(“F-Y”);
$remoteip = getenv(‘REMOTE_ADDR’);
$mytimestamp = date(“d/M/Y:G:i:s T”);
$useragent= getenv(“HTTP_USER_AGENT”);
$requri= getenv(“REQUEST_URI”);
$reqmet= getenv(“REQUEST_METHOD”);
$referrer= getenv(“HTTP_REFERER”);
$docroot= getenv(“DOCUMENT_ROOT”);
$logdir= $docroot . “/bloglog”;
$fplog = fopen($logdir .”/accesslog-myblog-“.$monthyear.”.txt”, “a+”);
fprintf ($fplog, “%s – [%s] \”%s %s\” \”%s\” \”%s\” 200\n”,
$remoteip, $mytimestamp,
$reqmet, $requri,
$useragent, $referrer);
fclose ($fplog);
?>

Doing so, a web access to any page of my site will add a log line into the accesslog-myblog-August-2012.txt  file. This file is into a directory named bloglog at the root of the webpages.

Getting this file and putting it on a linux box with awstats installed, it’s easy to generate my web statistics.

 

First I have to create a /etc/awstats/awstats-myblogname.conf telling my LogFile path and my LogFormat

LogFormat = “%host – %time1 %methodurlnoprot %uaquot %refererquot %code”

Then I have to run

 /usr/share/awstats/tools/awstats_updateall.pl now         -configdir=”/etc/awstats”         -awstatsprog=”/usr/share/awstats/wwwroot/cgi-bin/awstats.pl”

in order to read my stats at http://my-awstats-server.local/awstats/awstats.pl?config=myblogname

Tags: ,

Leave a Reply