Solved

Script to Count Links/Page Hits

Posted on 2001-06-29
6
209 Views
Last Modified: 2013-12-25
Hello,

Looking for CGI code (probably in perl) that keeps a count of the number of times each page in site is accessed as well as the number of times the links on the pages are hit on a monthly basis broken down in hourly time intervals. Output continually updates a MMMLinkCount.txt file and MMMPageCount.txt report in ./data directory with | delimiter. These files then can be loaded into Excel for creating spreadsheets and graphics.

JanLinkCount.Txt:

Date|Time|Page|Link|# Link Hits
01-01-01|00:00-01:00|index.htm|faq|5
01-01-01|00:00-01:00|index.htm|guest book|7
etc.

JanPageCount.txt:

Date|Time|Page|Link|# Link Hits
01-01-01|00:00-01:00|index.htm|12
etc.

Thanks in advance

0
Comment
Question by:zipdog44
  • 3
  • 3
6 Comments
 
LVL 8

Accepted Solution

by:
bebonham earned 200 total points
ID: 6239867
perhaps your server can provide you with such information?

I know a program that parses your server logs could, because your server can log every hit to every page on your site...and the ip of the visitor...and date and time of course...
now all that is left is to get all the the hits from the same ip together, and then sort them by time...then by some tricky logic that will know what links are on each page (an array of arrays with that information) you will see if that person has followed a link or typed in a new url...

the only place such a program might fail is if the person type the url of a LINK on that page into the address bar...the program would assume that the browser followed the link, and didn't type that in...

the reason I am suggesting this is here.

doing a counter for each page is fine, that can happen on page load...but counting the links hits on each page presents a problem...all your links will have to mess with the cgi as well...or you will be using a good bit of javascript...either way...you are now making a cgi dependant on very specific html and javascript features...that you will have to add to every page...and every new page.

HOWEVER, it can definitely be done, and I already have the solution in mind, as I have done similar before...


for instance...we could change the src of a 1px by 1 px img to the script with a query string indicating what action (link, new page, etc) was taken by the browser.

I strongly suggest you look into parsing the web server log file...

that is your best bet to get the info, becuase then you won't bog your server with that extra traffic on EVERY page.

I also believe there is premade software avail. for this purpose, and I will see if I can find such.


which way to you want to progress?


Bob
0
 
LVL 8

Expert Comment

by:bebonham
ID: 6239883
0
 

Author Comment

by:zipdog44
ID: 6240881
Thanks for the link.

Some problems I see.

Using Apache web server on solaris.

Products seem geared to Microsoft.
None of the products seem to count number of
time a link is hit.

I think a new product needs development to
get this information what about u?. If interested
I would like to work with u on developing the product.
I think it could be a success?

Thanks
Tom
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 

Author Comment

by:zipdog44
ID: 6250267
Log file does not record link information but I found this solution in "Writing CGI Applications with Perl" by kevin Meltzer and Brent Michalski for keeping a count of links in a MySql database

Create table

CREATE TABLE click_tracker (

     PAGE varchar(255) NOT NULL,
     COUNT int(11) NOT NULL,
     LAST_ACCESS datetime
);


Script:

#!/usr/bin/perl ?wT
# track.cgi
use strict;
use DBI;
use CGI qw(:standard);
use POSIX;
my $dbname = 'tomatocans';
my $dbhost = 'localhost';
my $dsn = "DBI:mysql:database=$dbname;host=$dbhost";
my $dbh=DBI-connect($dsn,"tomatocans","nakedtest");
if (!defined($dbh)) {
     print header; print "\nerror: There is a problem connecting to the MySQL database:\n";
     print DBI-errmsg;
     print "-" x 25; exit;
}
my $url = param('url');
my $time = strftime("%Y-%m/-%d %I:%M:%S", localtime);
my $query = qq(update click_tracker set COUNT=COUNT+1, LAST_ACCESS='$time' where PAGE='$url');
my $sth = $dbh-prepare($query);
if ($sth->execute <1){
    $query == qq(insert into click_tracker(PAGE,COUNT,LAST_ACCESS) Values('$url', 1, '$time'));
    $sth =  $dbh->prepare($query);
    $sth-execute;
}
$dbh-disconnect;
print redirect($url);



0
 

Author Comment

by:zipdog44
ID: 6250278
Your answer helped raise more questions. See last comment to see how I am proposing to solve Link Count. Still need to solve page count but i did not get any response from you so I wanted to remove question for EE.

If u want to participate more actively in the solution please feel free to email me at tomatocans@aol.com


Thanks
0
 
LVL 8

Expert Comment

by:bebonham
ID: 6254128
I was on vaccation...

no problem, I will email you with some help!
as your question is interesting.


Regards,

Bob
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

I hope you'll find this tutorial useful and interesting. So let's try to extend Tcl with a new package.  For anyone more deeply interested please check out the book "Practical Programming in Tcl and Tk". It's really one of the best written books abo…
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now