Note - I haven't tried this yet, so try it at your own risk!
If your server's CGI access (assuming it has it) supports SSI (server-side includes), you can write a Perl script to collect the URLs that visitors come from, and write a report program.
If you are using a UNIX system, you will need to set the file permissions to make them executable as follows: chmod 755 filename.pl
For an FTP program (e.g. WS_FTP), set all options to read and execute. Also set the "write" option for "owner".
Create an empty file called Sources.Log, and upload it to your server. For Unix, set all permissions for this file to read, write, and execute; for a chmod command, this will be 777.
Name your Web page with the .shtml extension, so that the Web server will parse each line in the file and therefore find the command to run the script.
To add the first script on your page, include an SSI command to run the script as follows:
<!--#exec cgi="cgi-bin/filename.pl" -->
Here is the script:
# specify the perl path
#!/usr/bin/perl
# SCRIPT TO TRACK YOUR SITE AUDIENCE
# Specify the log file that stores the referring URLs. The record format of
# each line is XX www.somewhere.com where XX is the number of people who have
# come from that page. There is a line for each site, and it is case sensitive.
# Modify the relative path of the log filename if appropriate.
$source_file = "../logs/Sources.Log";
# Get the URL of the previous page the visitor was viewing. Note, you are not
# getting any user information. Store the URL in a variable called
# $source_url.
$source_url = $ENV{'HTTP_REFERER'};
# if there is no URL, assume the typed in page or used bookmark
unless ($source_url)
{ $source_url = "Direct Hit"; }
# open and read the log file that stores the referring URLs
open(source_file,"$source_file");
flock(source_file,2);
# put the data into an array named @sources
@sources = <source_file>;
close(source_file);
# remove the last character from the string
chop(@sources);
# look at each line in the array, one by one
foreach $refer (@sources)
# Separate separates the number from the URL. The blank space between the two
# slashes tells Perl to assign anything before the space to the variable
# $number, and anything after the space to the variable $url.
{ ($number,$url) = split(/ /,$refer,2);
# Comparison of URL captured above and URL of current record of referring
# URLs file
if ($url eq $source_url)
# If there is a match, increment the number against that URL in the referring
# URLs file
{ $number++;
# If there is a match, reassemble the number and the URL back into a single
# line.
$refer = "$number $url";
# If there is a match, create a variable called $found to indicate we've found
# a match for the current visitor's referring URL.
$found = "true";
}
}
# If not found,
unless ($found)
# If not found, create a new entry in the log file with number - 1, and the URL
# this user came from
{ $url = "1 $source_url";
# If not found, add, (push) the new entry to the @sources array.
push (@sources,$url);
}
# Write the newly modified @sources array to the log file
open(source_file,">$source_file");
foreach $refer (@sources)
{ print source_file "$refer\n"; }
# Close the log file
close(source_file);
# what does this do?
flock(source_file,8);
You could simply read the log file, but you can also use another script to write a report.
Back to top Home Serious Stuff
© 2001. Copyright Sue Nethercott.