Print Page | Close Window

Script to count # of times a page is viewed

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: Classic ASP Discussion
Forum Description: Discussion on Active Server Pages (Classic ASP).
URL: https://forums.webwiz.net/forum_posts.asp?TID=28242
Printed Date: 28 March 2026 at 2:21pm
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: Script to count # of times a page is viewed
Posted By: iSec
Subject: Script to count # of times a page is viewed
Date Posted: 14 January 2010 at 8:39pm
Hello everyone,

I'm looking for a classic ASP-based code / script that counts the number of times a page is viewed. Just like here on the forum when a thread is viewed the # increases every time a user views that topic.

Example: This page has been viewed _______ times.



Replies:
Posted By: 123Simples
Date Posted: 15 January 2010 at 7:00pm
Stat Counter http://www.statcounter.com/ will do it

-------------
http://www.123simples.com/" rel="nofollow - Visit 123 Simples Web Design


Posted By: 123Simples
Date Posted: 15 January 2010 at 7:00pm
You can even then edit around that to say
This Page Has Been Viewed (then stat counter code) times Wink


-------------
http://www.123simples.com/" rel="nofollow - Visit 123 Simples Web Design


Posted By: iSec
Date Posted: 15 January 2010 at 11:23pm
That uses PHP and that's not what I'm looking for. I'm looking for an ASP-based script because the site I intend to use this on is of classic ASP. 

-------------
"When it gets dark enough, you can see the stars"
-Charles A. Beard


Posted By: iSec
Date Posted: 15 January 2010 at 11:29pm
I found one that accomplishes exactly what i asked for, and here it is if anyone needs it:

http://www.psacake.com/web/iv.asp" rel="nofollow - http://www.psacake.com/web/iv.asp

**Note: this is not listed on that page but you need to create a count.txt file and grant read/write access to it, for this script to work.


-------------
"When it gets dark enough, you can see the stars"
-Charles A. Beard


Posted By: dpyers
Date Posted: 16 January 2010 at 7:07pm
On asp pages, also make sure that pages aren't being viewed from the browser or a proxy cache:

Set:
Response.CacheControl="Private"

This is to prevent proxy servers from caching the page. It's supposed to be the IIS default but some web hosts set it to Public by default to allow caching and reduce load on their servers.

Also set:
Response.ExpiresAbsolute=#January 16,2010 16:00:00#
Set this to the current date/time to ensure that the page expires from the browsers cache as soon as it's viewed.

These two commands change the HTTP headers for the page.
Setting page expiration using HTML meta tags is not reliable across all browsers.


-------------

Lead me not into temptation... I know the short cut, follow me.


Posted By: iSec
Date Posted: 17 January 2010 at 12:03am
dpyers, thanks for the tip... i needed that, especially the expiration one Thumbs Up

-------------
"When it gets dark enough, you can see the stars"
-Charles A. Beard


Posted By: dpyers
Date Posted: 18 January 2010 at 3:26am
Even changing the http header content sent by the servers isn't 100% reliable. Some ISP's and internet services offering a "faster" internet ignore the http header info as well and run their own cache's to server up pages quicker.

Counter services typically force the retrieval of an image or file from another ip address. often using a variable link. It adds another layer to what would need to be cached to replicate the page without actually retrieving it but large ISP's cache millions of pages/files.

Google has put a lot of pressure on ISP's to respect header info and the problem isn't as acute as it's been in the past.
For most of us, missing a count or two is not a big deal. If it really matters to your site though, a strategy involving http_referer, cookies, remote images, and db updates can eliminate the misses.
You won't see a good return on your investment in time to set it up, but for some sites, accuracy is more critical than for most sites.

On the flip side of the coin, some browsers can preload pages linked to the current page. You make get a hit, but no eyeballs actually viewed the page.


-------------

Lead me not into temptation... I know the short cut, follow me.


Posted By: iSec
Date Posted: 31 January 2010 at 12:59am
dpyers, sorry about the late response... thanks for sharing these valuable tips and advices!

-------------
"When it gets dark enough, you can see the stars"
-Charles A. Beard



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net