Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Displaying multiple hidden counter results on a separate page

Status
Not open for further replies.

RexDart

Programmer
May 22, 2002
8
US
Here's what I'd like to do...

My company hosts simple, online "ads" for several companys. These ads usually consist of 2 to 3 html pages. I would like to have a hidden counter on each company page, and have the results for each page be displayed on a separate "results" page, so that they can view the amount of hits each of their pages receive.

Example... Baskin Robbins Ice cream has 2 pages, an about us page, and a specials page. I want to have a third page called results that displays the # of hits the other 2 pages have received (ex. one counter display for about us, one counter display for specials, etc.).

I'm trying to find the easist way to give the ability for each of our clients to open a webpage in their directory, and see the counter results without showing them to the rest of the world.

Can someone point me to a script available online that will allow me to do this? Thanks...
 
Your web logs should contain that information. I'd look to reading/parsing/reporting the web log info. You could set it up as a cron job to run every night or every hour or what ever period makes sense.

'hope this helps

If you are new to Tek-Tips, please use descriptive titles, check the FAQs, and beware the evil typo.
 
Yes, I do have access to my server's weblogs, however, I have no experience with parsing data from the logs. Are there any guides / tutorials on the web that you could point me to? Thanks...
 
This illustrates reading a log file, building a hash of urls and associated hits and then print a sorted list of those urls and hits. Unless you are running apache with your log formatted just like ours, you'll need to tweak the logic or pattern matching to catch the url and hits.


Code:
#!/usr/local/bin/perl -w
# parses an apache access_log and reports a sorted list
# of hits
use strict;

# open/read the web log
open(WEBLOG,"/httpd/logs/access_log");
my @recs = <WEBLOG>;
close WEBLOG;

# use a pattern match to catch the url requested and
# build a hash of urls and associated number of hits.
my %urls;
foreach my $rec (@recs) 
    {
    # Your web logs may likely follow a different format.  If
    # so, you'll need to adjust your pattern match accordingly.
    # This matches/catches pattern chunks from a line like
    # 123.456.678.910 - - [03/Jun/2002:08:14:43 -0400] &quot;GET /path/to/image.jpg HTTP/1.0&quot;....
    if ($rec =~ /.*?-.*?- \[.*?\] &quot;\w+ (.*?) .*$/) { $urls{$1}++; }
    }


foreach my $url (reverse (sort {$urls{$a} <=> $urls{$b}} (keys %urls)))
    {
    print &quot;HITS: $urls{$url} - URL: $url\n&quot;;
    }
'hope this helps

If you are new to Tek-Tips, please use descriptive titles, check the FAQs, and beware the evil typo.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top