By Alvin Alexander. Last updated: June 4, 2016
There was a little funky activity on a client's Drupal 6 website that was hosted at GoDaddy, and without having access to an Apache access log file, I wanted to be able to see what was going on. So I wrote the following PHP code snippet to do some manual logging, and placed it in the Drupal theme's page.tpl.php
file:
<?php $ip = $_SERVER['REMOTE_ADDR']; $today = getdate(); $day = $today['weekday']; $month = $today['month']; $hour = $today['hours']; $minute = $today['minutes']; # drupal $curr_uri = check_plain(request_uri()); # use this for a plain php page (non-drupal) # $curr_uri = $_SERVER['REQUEST_URI']; $format = "%s %s, %s:%s, %s, %s\n"; $text = sprintf($format, $month, $day, $hour, $minute, $ip, $curr_uri); $filename = '/var/chroot/home/content/xx/uid/tmp/access_log'; $fp = fopen($filename, 'a'); fwrite($fp, $text); fclose($fp); ?>
Most of the code is plain PHP code, except for the check_plain(request_uri())
, which is Drupal-specific.
If you ever need to do some manual access logging like this on a Drupal website, I hope this PHP code snippet is helpful.