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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating Hit Counter

Status
Not open for further replies.

Developer2U

Programmer
Nov 25, 2005
28
0
0
US
I want to create a hit counter for my web site. I have some ideas on how to implement this but I'm looking for feedback from more experienced people.

1- I will have to store this hit counter in either a database or some other file, perhaps an xml file. Which is better? I tried opening a database connection on application start and later found that is a big no no. Plus I got a lot of errors from it.

2- When do I access and return the current hit counter? I am assuming on Application Start or maybe Session Start?

3- When do you add to the current hit counter? At Session End?

Thanks...
 
First, you'll have to decide whether this is a hit counter for each page or the whole site (e.g. do you want different counters for each page or one counter for the whole site).

Then, you have to decide when you want it to update (e.g. should the counter increase each time a page is requested or just once when a user comes to your site).

Having a database/file hit for each time a page is requested would seem unneccessary to me. You could just keep an application variable with the counter as long as you know that you may have to store this elsewhere every so often in case the application goes down.


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Thanks for your response. I found a code snippet online that made use of a static class called Visits that interfaced with a database.

I want to maintain a hit counter for the application as a whole, not for individual pages. I would think at session_start would be a good place to increase the counter. Am I correct?

This works, but I think your recommendation not to use the database is compelling.

Do people normally use a text, binary or xml file for this, or is it a matter of preference.

 
Yeah, the Session Start event is probably the best place to increment the value in my opinion.

As for storing the variable, I would consider only doing it every so often (i.e. keep an application variable and every x hours or so update a database or file with this value).


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top