Solved

Perl CGI Counter randomly skips

Posted on 2004-04-06
15
261 Views
Last Modified: 2013-12-25
I am using the code below to count hits on a web site.
Problem is it randomly skips on the tenth digit?
      For example 10 may show up but 20 shows as 10..:
      5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,10,21,22,23,24,25,26,27,28,29,20,31,32
This is random.. sometimes the tenth digit is correct sometimes it doesn't increment until the last digit hits 1.

This does not use FLY or SSI.. it is called with the following html:
          <img src="http://website/cgi-bin/counter.cgi?1">  
          <img src="http://website/cgi-bin/counter.cgi?0&w">

Here's the code:
---------------------------------------------------------------
  $digits_basedir = "http://website/cgi-bin/counter/";
  $count_file = "count";
($place, $Write) = split(/\&/,$ENV{QUERY_STRING});

open(COUNT,"$count_file") || die "Can't Read From Count File $count_file, Error : $!\n";
($count) = <COUNT>;
close(COUNT);
$count =~ s/\n//;

if ($Write =~ /w/i) {
   $count++;
   open(COUNT,">$count_file") || die "Can't Write To Count File $count_file, Error : $!\n";
   print COUNT "$count";
   close(COUNT);
}
$count = "0000000000".$count;
@chiffres = split(//, $count);
@chiffres = reverse(@chiffres);
print "Location: ".$digits_basedir.$chiffres[$place].".gif\n\n";
0
Comment
Question by:Stella Pauley
  • 8
  • 7
15 Comments
 
LVL 2

Expert Comment

by:healthstatus
ID: 10766625
I'm guessing the browser or your ISP is caching the image since the URL for the digits isn't changing.  Try adding a &x to the  <img src="http://website/cgi-bin/counter.cgi?1">   so it becomes  <img src="http://website/cgi-bin/counter.cgi?1&x">   that may get the cache into thinking it is dynamic (which it doesn't think it is currently).  The other thing to try is get to 19. close the browser, clear your cache and then go to the page and see if it pops up as 20.
0
 
LVL 1

Author Comment

by:Stella Pauley
ID: 10766755
I set it to &x and had the same problem.
I also ran it up to 119, closed the browser, opened browser, deleted cache files, then hit the page and got 110 instead of 120. then 121..

Thanks, any other ideas?
0
 
LVL 2

Expert Comment

by:healthstatus
ID: 10766981
I may be barking up the wrong tree, but I still think it is a cache issue, probably the ISP or your network proxy server.
You might try putting the meta tags:
<META HTTP-EQUIV="Pragma" CONTENT="no-cache" />
<META HTTP-EQUIV="Expires" CONTENT="-1" />
on your web page and see if that makes any difference.
0
 
LVL 1

Author Comment

by:Stella Pauley
ID: 10767051
Same results with the meta tags.
Same results with or without going through a proxy.
0
 
LVL 1

Author Comment

by:Stella Pauley
ID: 10767116
You may be right on the caching though..
When the web shows 250 the count text file shows 260.
0
 
LVL 2

Expert Comment

by:healthstatus
ID: 10767118
Try changing

print "Location: ".$digits_basedir.$chiffres[$place].".gif\n\n";

to

print "Location: ".$digits_basedir.$chiffres[$place].".gif?".$count.'\n\n";

0
 
LVL 2

Expert Comment

by:healthstatus
ID: 10767124
oops - typo

print "Location: ".$digits_basedir.$chiffres[$place].".gif?".$count."\n\n";
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 1

Author Comment

by:Stella Pauley
ID: 10767237
same results...
0
 
LVL 2

Expert Comment

by:healthstatus
ID: 10767268
Really!? When you right click (windows I hope) the image and look at the properties what does it show as the URL for the images? or look at the source.
0
 
LVL 1

Author Comment

by:Stella Pauley
ID: 10767321
properties of each image show:
http://website/cgi-bin/counter.cgi?1&x

images are layed out as:
4&x  3&x  2&x  1&x  0&w

Here's the "View Source" (yes its windows)
----------------------------------------------
<HTML>
<head>
<META HTTP-EQUIV="Pragma" CONTENT="no-cache" />
<META HTTP-EQUIV="Expires" CONTENT="-1" />
</head>
<body>
<img src="http://website/cgi-bin/counter.cgi?4&x">
<img src="http://website/cgi-bin/counter.cgi?3&x">
<img src="http://website/cgi-bin/counter.cgi?2&x">
<img src="http://website/cgi-bin/counter.cgi?1&x">
<img src="http://website/cgi-bin/counter.cgi?0&w">
</body></HTML>
0
 
LVL 2

Expert Comment

by:healthstatus
ID: 10767387
Do you have the ability to change the links to https (page and the image links)? Just for the sake of testing?
0
 
LVL 1

Author Comment

by:Stella Pauley
ID: 10767612
Ability... Yes...
But I don't have a Certificate file for the ssl..

IIS v5.1
0
 
LVL 2

Accepted Solution

by:
healthstatus earned 500 total points
ID: 10767662
Well that will just pop a certificate error in your browser but still load the page, usually networks won't cache https pages.  I guess from what I see, it is not a coding issue, other than the technique used is susceptible to problems.
0
 
LVL 1

Author Comment

by:Stella Pauley
ID: 10768037
IIS won't let me use ssl without a certificate file..

Thanks for the help..
0
 
LVL 1

Author Comment

by:Stella Pauley
ID: 10775092
I found the problem.. the &w was in the wrong spot..
I had it pulling image 4, 3, 2, 1, writing to the log file, then pulling image 0...

I moved the &w first image source (the one with a 4) instead of the on with the 0..
this way it writes to the log file then pulls image 4, 3, 2, 1, 0...

I still did need the cache disabled.. without that it then randomly skipped any digit..

Thanks for the help...
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
i want to read the contents of the file to Csv 13 53
Update a registry value to every user hive 15 72
Sed question 2 69
how to pick specific file from ftp 13 40
Introduction:   Welcome to my first article ever. To begin with, the reason I write this article.  I participated in a question on Experts Exchange about the start command in Windows and there were some discussion about the usage. The discussio…
Recently I have been answering a lot of questions like this in IT forums that I frequent. The question posed is usually something along the lines of "We have software X installed and need to uninstall it for reason Y" or some other variant of the sa…
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…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

895 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

16 Experts available now in Live!

Get 1:1 Help Now