Jump to content

hit counter


Birdofprey

Recommended Posts

Which is the best approach?

I queue a mysql table with current hits number, let say 3.
do num++ whenever a page loads.
And add the current number back to the table.

Or

Use session to record the pageview and add it to the table?
If I were to use session where I begin since I never had any experience with sessions.
Link to comment
Share on other sites

[!--quoteo(post=369031:date=Apr 26 2006, 05:59 PM:name=DepretioN)--][div class=\'quotetop\']QUOTE(DepretioN @ Apr 26 2006, 05:59 PM) [snapback]369031[/snapback][/div][div class=\'quotemain\'][!--quotec--]
Write the value to a text file. Each hit, pull the value from the text file, increment it, put it back in the text file.
[/quote]

Why this approach? I've looked at many simple hit counter script, majority of which uses text based, but I don't want to use it because I would end up with a bunch of txt files.
Link to comment
Share on other sites

in the end, it's mostly just a matter of preference whether you want to store the number in a sql database or a text file, for something that simple.

as far as sessions are concerned, it depends on how restricted you want your counter to be. do you want it to go up every time any random person views the page, even if they keep clicking the refresh button, or do you want it to only increment for unique users (ip addresses)? do you want the counter to be user specific (as in, "you have viewed this page x amount of times, Richard") ?
Link to comment
Share on other sites

[!--quoteo(post=369118:date=Apr 27 2006, 01:04 AM:name=Crayon Violent)--][div class=\'quotetop\']QUOTE(Crayon Violent @ Apr 27 2006, 01:04 AM) [snapback]369118[/snapback][/div][div class=\'quotemain\'][!--quotec--]
in the end, it's mostly just a matter of preference whether you want to store the number in a sql database or a text file, for something that simple.

as far as sessions are concerned, it depends on how restricted you want your counter to be. do you want it to go up every time any random person views the page, even if they keep clicking the refresh button, or do you want it to only increment for unique users (ip addresses)? do you want the counter to be user specific (as in, "you have viewed this page x amount of times, Richard") ?
[/quote]

at first I wanted to just display amount of times page was viewed, but then I realized anyone should just refresh the page over and over and just increase the number, which then seems like a foolish idea because it whould be a unnesscary waste of server's resources.
Now, I decide that I want to count only unique ips, lets say every 12 hours or so.
Could I still use sessions, or now I would have to go into cookies?
Link to comment
Share on other sites

you don't really need either. just make another column in the database (or format your text file if you wanna go that route, but i'll use the db example) named like ipaddress or something. then, all you have to do is when the hit counter script runs, see if the user's ipaddress is already on the list. if it is, then do not increment the counter. if it is not, then increment the counter and insert the ip address onto the list.

Link to comment
Share on other sites

[!--quoteo(post=369410:date=Apr 27 2006, 08:38 PM:name=Crayon Violent)--][div class=\'quotetop\']QUOTE(Crayon Violent @ Apr 27 2006, 08:38 PM) [snapback]369410[/snapback][/div][div class=\'quotemain\'][!--quotec--]
you don't really need either. just make another column in the database (or format your text file if you wanna go that route, but i'll use the db example) named like ipaddress or something. then, all you have to do is when the hit counter script runs, see if the user's ipaddress is already on the list. if it is, then do not increment the counter. if it is not, then increment the counter and insert the ip address onto the list.
[/quote]
if I put the ip onto the list, it will be there forever, no?
what if I want is count a unique ip every 24 hours?
Link to comment
Share on other sites

well then you could make yet another column with a timestamp in it and either have the script before anything else, delete all ip addresses older than 24 hours. or you could setup a cron job to do that.

or.. you could make a cookie that expires in 24 hours and have your script check for the cookie and if it exists, then don't increment the counter. but accurate hits would be dependant on everybody having cookies enabled on their system.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.