Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Counter

Counter
Thread Tools
Addicted to MacNN
Join Date: Jan 2000
Location: Stoneham, MA, USA
Status: Offline
Reply With Quote
Feb 10, 2002, 09:29 PM
 
I wanna make my own counter for my page i host on my own web server. I can figure out how to write such a script in perl. But how do I insert it into my page without having to have the CGI return the whole page? I still want my page to be a regular HTML file??
     
Grizzled Veteran
Join Date: Jun 2001
Location: Melbourne, Australia
Status: Offline
Reply With Quote
Feb 11, 2002, 04:52 PM
 
Originally posted by l008com:
<STRONG>I wanna make my own counter for my page i host on my own web server. I can figure out how to write such a script in perl. But how do I insert it into my page without having to have the CGI return the whole page? I still want my page to be a regular HTML file??</STRONG>
You may need it convert it into an .shtml file, and insert a SSI which calls your CGI. E.g.

&lt;p&gt;You are visitor number &lt;!--#include "/path/to/your/counter.cgi" --&gt; to this site&lt;/p&gt;

This is assuming your CGI is writing text, obviously.

If you're a clever clogs and you want to write a CGI that returns an image instead (but PLEASE don't use that 'orrible LCD typeface ) then you would put something like:

&lt;p&gt;You are visitor number &lt;img src="/path/to/your/counter.cgi" height="40" width="40" alt="Counter"&gt; to this site&lt;/p&gt;

And make sure your webserver has the module for SSI turned on and the appropriate &lt;directory&gt; settings as well.

[ 02-11-2002: Message edited by: Simon Mundy ]
Computer thez nohhh...
     
Administrator
Join Date: May 2000
Location: California
Status: Offline
Reply With Quote
Feb 14, 2002, 10:24 PM
 
Must the counter be visible on the page? I added counters to the Team site, but reasoned that visible counters are tacky, and really of interest only to the site owner / webmaster.

So I embedded some PHP code in each page file, to append a character to a text hit file on the server. Each time the page is loaded, the hit file becomes one character longer. Check the hit file for byte length, and you have the hit count for that page. Delete the hit file to reset the counter.

I added an unlisted page to show the hits on each of our site pages, and give the option to zero each or all counters.

As a plus, this solution does not show in the page source, so it doesn't slow down page loading. This can be important to modem users like myself.
     
Occasionally Useful
Join Date: Jun 2001
Location: Liverpool, UK
Status: Offline
Reply With Quote
Feb 14, 2002, 10:32 PM
 
Originally posted by reader50:
<STRONG>As a plus, this solution does not show in the page source, so it doesn't slow down page loading. This can be important to modem users like myself.</STRONG>
using the above .shtml method and inserting &lt;!--#include "/path/to/your/counter.cgi" --&gt; in your page doesn't show in your page source either though. it doesn't slow stuff down either

when you said:
Each time the page is loaded, the hit file becomes one character longer.
did you really mean longer? as in "1+1+1+1+1+1+etc", resulting in a huge line of numbers, as opposed to having, say, counter.dat with just one figure in it? that seems a bit odd to me, can you show me what you mean?
"Have sharp knives. Be creative. Cook to music" ~ maxelson
     
l008com  (op)
Addicted to MacNN
Join Date: Jan 2000
Location: Stoneham, MA, USA
Status: Offline
Reply With Quote
Feb 14, 2002, 10:37 PM
 
Well I actually want a visible counter. I already made the ten gif digits, a perfect match, and i got server side includes working, now the only part left is making the counter itself, that is goona be tricky because i always have bad luck with perl. And i'd like to have it ignore all 192 IP's, or at least 192.168.0.2 so it doesn't count me at home. Any help with this part of the mission would be greately appriciated. :-D By the way does BBEdit or BBEdit Lite have color coded perl syntax?
     
Occasionally Useful
Join Date: Jun 2001
Location: Liverpool, UK
Status: Offline
Reply With Quote
Feb 14, 2002, 10:46 PM
 
"Have sharp knives. Be creative. Cook to music" ~ maxelson
     
Administrator
Join Date: May 2000
Location: California
Status: Offline
Reply With Quote
Feb 14, 2002, 11:25 PM
 
Originally posted by philzilla:
<STRONG>
did you really mean longer? as in "1+1+1+1+1+1+etc", resulting in a huge line of numbers, as opposed to having, say, counter.dat with just one figure in it? that seems a bit odd to me, can you show me what you mean?</STRONG>
It's more like this:
<BLOCKQUOTE><font size="1"face="Geneva, Verdana, Arial">code:</font><HR><pre><font size=1 face=courier>
$HitsFile = <font color = red>"datafolder/hits008.txt"</font>;
$HitsCount = fopen($HitsFile, <font color = red>"a"</font>);
fputs($HitsCount, <font color = red>"."</font>);
fclose($HitsCount);
</font>[/code]
Change the hitfile number for different pages.

When you read the hit count, you do not open the file. Instead, you retrieve the file length from the filesystem. This should always be faster than opening the file. The exact character used to append to the file doesn't matter. I used a period, but anything would do.

I chose not to write out an actual number, because I'd have to open the file to read it. Even worse, if the page were loaded by more than one person at once, it would be possible for multiple threads to attempt writing to the file at the same time. Even if they succeeded without messing up, the counter would be incorrect, counting only one of the simultaneous hits.

Append works better, and should work correctly regardless of how many hits the page takes at the same time.

Oh, and by slowing down the page load, I meant more than having code show in the source. With this method, nothing shows, and no graphics have to load. A text counter would amount to about the same thing, but a graphic counter just slows the modem down that much more.

[Edit] I wish parallax would get around to making the code tag easily editable.

[ 02-15-2002: Message edited by: reader50 ]
     
l008com  (op)
Addicted to MacNN
Join Date: Jan 2000
Location: Stoneham, MA, USA
Status: Offline
Reply With Quote
Feb 14, 2002, 11:28 PM
 
Interesting way of doing it, but what happens when you get a billion hits?

HA! You didn't think of that one did you!?
     
Administrator
Join Date: May 2000
Location: California
Status: Offline
Reply With Quote
Feb 14, 2002, 11:42 PM
 
Originally posted by l008com:
<STRONG>Interesting way of doing it, but what happens when you get a billion hits?

HA! You didn't think of that one did you!?</STRONG>
Actually, I did, read my (edited) post please.

Oh, and we get about 1,100 hits per day across the various pages.
     
l008com  (op)
Addicted to MacNN
Join Date: Jan 2000
Location: Stoneham, MA, USA
Status: Offline
Reply With Quote
Feb 14, 2002, 11:46 PM
 
And those don't count the forums do they? These forums are so great I put a UBB on my own web site, for friends and family to use!!! No one EVER does :-( oh well, back to the counter...
     
l008com  (op)
Addicted to MacNN
Join Date: Jan 2000
Location: Stoneham, MA, USA
Status: Offline
Reply With Quote
Feb 18, 2002, 01:18 AM
 
OK I got it working perfectly now. This particular thread has served its purpose well, time to say goodbye, and on to the next challenge.
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 06:05 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2