stefan and zogo small Help Stefan Campaign
If you can spare $1 then help support this site and change someone's life forever? Learn how and why on the Help Stefan campaign page. Or donate $10 and get my guide to spices book as a gift for your donation!


Celtnet Information:

How to Create your Own Site Access Log

As I found to my cost, not all UNIX hosting environments come with full access logs. Initially this wasn't a problem for me as I was mostly fixed on growing my website and on getting the basic advertising and publicity for my website going. Indeed, between varous mechanisms I managed to increase the traffic to my site over 30x (to learn how I managed this see my How to Maximize your Web Traffic page). But certain areas of the site seemed to be preforming much better than others. I knew which those areas were based on Google AdWords campaigns, but I had no idea whether that was because I wasn't getting enough visitors to those areas of the site or whether the ads on those pages just weren't converting. This is where the absense of proper server logs began to be a major problem. How was I to know what my website was doing when I just didn't have the information about who was visiting those pages. Were they even being crawled by the web indexing bots?

Of course, my ISP had the option of ading logging to my site. But that was an additional £3.99 ($8.00) a month on top of what I was already paying them. As a programmer (and needing all the money I can get for other things) I decided to see if I couldn't circumvent this problem myself. After all, with the various programming languages I know, surely I could come up with a way of doing this for myself.

A little head scratching and some playing with various bits of code later and I had something that could create just what I wanted: a site access log.

Site Access Logs

A site access log is basically a text file that stores a record of who visits your site and when. It can either just tell you who's come to your site or it can tell you precisely which page they've visited. This can be invaluable information to let you know where people are coming into your site and where they are not. Such logs also let you know peoples' behaviour on your site. Are they staying to expore, or are they just coming into a single page and then leaving. With this information you can help increase the 'stickiness' of your site to make it more visitor-friendly. Or you can seek to chage visitors' behaviour to drive them to areas of the site that generate more revenue for you.

If you know things like how a visitor moves through your site or how many seconds it takes for a visitor to navigate from one page to another you can start playing with your site to optimize your pages and the layout of your site so that it can perform better.

In the end log files can be critical for your website's performance. If you don't have one, then you need one. It's a critical component in your armoury of internet marketing tools.

The Script

The script I produced is given in its entirety below. For it to work you need to create a directory in the base level of your website called 'logs'. All files created by the logging script will be saved in the 'logs' directory. You need to create this directory as, for security reasons, the script does not create directories for you. The script itself is as below.

<?php

//ASSIGN THE BASIC VARIABLES FOR YOUR VISITOR
$time = date("M j G:i:s Y");
$ip = getenv('REMOTE_ADDR');
$userAgent = getenv('HTTP_USER_AGENT');
$referrer = getenv('HTTP_REFERER');
$query = getenv('QUERY_STRING');

//COMBINE VARS INTO OUR LOG ENTRY
$msg = "IP: " . $ip . " TIME: " . $time . " REFERRER: " . $referrer . " USER-QUERY: " . $query . " USERAGENT: " . $userAgent;

//CALL THE CENTRAL FUNCTION TO WRITE TO THE LOG FILE
writeToLogFile($msg);

function writeToLogFile($msg)
{
      $today = date("Y_m_d");
      $logfile = $today."_log.txt";
      $dir = 'logs';
      $saveLocation=$dir . '/' . $logfile;
      if (!$handle = @fopen($saveLocation, "a"))
      {
           exit;
      }
      else
      {
           if(@fwrite($handle,"$msg\r\n")===FALSE)
           {
                exit;
           }

           @fclose($handle);
      }
}

?>


To get the script to work you can either place the code in every page that you want access to recorded in your logs. Alternaively (this is what I do), save the script somewhere as 'logging.php' then call the script in whichever pages you want logged via a PHP 'include' call of the tpye:

<?php

     include('/php/logging.php');
?>


This script prvides me with all the information I need to keep track of visitors to my site. The $msg variable being the text that's written to the log file. This variable can be set-up however you want to. It works with the parser I've written for the file, but it's not in the common logfile that's supported my all major servers. Still, the variable is easy enough to change and if you want to write output to your log file in that format simply change to output to comply with the W3C's definition. Note that the name for the log file use the ISO date format of Year_Month_Date. This both keeps to international standards and prevents the logs generated a year from today from over-writing today's log.

Include this script in all your PHP-based web pages and you can have full logs for your site (and you may even save yourself some money on your webhosting package!).

Search: php scripting


In association with Amazon.co.uk
  

1.
Search : PHP 6 and MySQL 5 for Dynamic Web Sites: Visual QuickPro Guide (Visual QuickPro Guides)
List Price: £28.99
Amazon.co.uk's Price: Â£14.49
You Save: £14.50 (50%)
Prices subject to change.
PHP 6 and MySQL 5 for Dynamic Web Sites: Visual QuickPro Guide (Visual QuickPro Guides)
by: Larry Ullman
April 02, 2008
 
2.
Search : PHP and MySQL Web Development (Developer's Library)
List Price: £31.91
Amazon.co.uk's Price: Â£15.99
You Save: £15.92 (50%)
Prices subject to change.
PHP and MySQL Web Development (Developer's Library)
by: Luke Welling, Laura Thomson
October 09, 2008
 
3.
Search : Sams Teach Yourself PHP, MySQL and Apache All in One (Sams Teach Yourself All in One)
List Price: £24.93
Amazon.co.uk's Price: Â£12.49
You Save: £12.44 (50%)
Prices subject to change.
Sams Teach Yourself PHP, MySQL and Apache All in One (Sams Teach Yourself All in One)
by: Julie C. Meloni
June 26, 2008
 
4.
Search : PHP Pocket Reference
List Price: £6.95
Amazon.co.uk's Price: Â£5.19
You Save: £1.76 (25%)
Prices subject to change.
PHP Pocket Reference
by: Rasmus Lerdorf
November 11, 2002
 
5.
Search : Advanced PHP Programming (Developer's Library)
List Price: £36.50
Amazon.co.uk's Price: Â£21.90
You Save: £14.60 (40%)
Prices subject to change.
Advanced PHP Programming (Developer's Library)
by: George Schlossnagle
March 04, 2004
 
6.
Search : PHP 5 Advanced: Visual Quickpro Guide (Visual QuickProject Guides)
List Price: £24.99
Amazon.co.uk's Price: Â£14.99
You Save: £10.00 (40%)
Prices subject to change.
PHP 5 Advanced: Visual Quickpro Guide (Visual QuickProject Guides)
by: Larry Ullman
March 12, 2007
 
7.
Search : Head First PHP & MySQL
List Price: £31.99
Amazon.co.uk's Price: Â£18.19
You Save: £13.80 (43%)
Prices subject to change.
Head First PHP & MySQL
by: Lynn Beighley, Michael Morrison
December 30, 2008
 
8.
Search : Prototype and Scriptaculous in Action
List Price: £31.99
Amazon.co.uk's Price: Â£19.19
You Save: £12.80 (40%)
Prices subject to change.
Prototype and Scriptaculous in Action
by: Dave Crane, Bear Bibeault, Tom Locke
March 21, 2007
 
9.
Search : Sams Teach Yourself PHP in 24 Hours (Sams teach yourself - hours)
List Price: £17.99
Amazon.co.uk's Price: Â£10.79
You Save: £7.20 (40%)
Prices subject to change.
Sams Teach Yourself PHP in 24 Hours (Sams teach yourself - hours)
by: Matt Zandstra
December 24, 2003
 
10.
Search : PHP and MySQL Web Development, 3rd Edition
PHP and MySQL Web Development, 3rd Edition
by: Luke Welling, Laura Thomson
September 29, 2004
 
page 1 of  6
 1  2  3  4  5  6 
 



Domain Name Registration




Quick Links:
Make Money from the Web
Essential Web Tools
Generate your Website
Paid Surveys
Affiliate Programmes
Successful Affiliates
Maximizing Traffic
News Feeds
Using Minisites
Form-mail script
Sitemap
Links
Celtnet Information Home


Site Search





[Valid RSS] Register Domains
Copyright © 2005–2007, Dyfed Lloyd Evans