Jump to content


Photo

hit counter


  • Please log in to reply
8 replies to this topic

#1 Birdofprey

Birdofprey
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 26 April 2006 - 09:49 PM

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.


#2 DepretioN

DepretioN
  • Members
  • PipPip
  • Member
  • 12 posts

Posted 26 April 2006 - 09:59 PM

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.

#3 Birdofprey

Birdofprey
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 26 April 2006 - 10:33 PM

[!--quoteo(post=369031:date=Apr 26 2006, 05:59 PM:name=DepretioN)--][div class=\'quotetop\']QUOTE(DepretioN @ Apr 26 2006, 05:59 PM) View Post[/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.

#4 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 27 April 2006 - 05:04 AM

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") ?

Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#5 Birdofprey

Birdofprey
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 27 April 2006 - 01:44 PM

[!--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) View Post[/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?

#6 Orio

Orio
  • Staff Alumni
  • Advanced Member
  • 2,491 posts

Posted 27 April 2006 - 04:56 PM

Sessions get destroyed after the browser is closed.
Cookies is good, but theres always people who dont accept, delete or whatever.
But on the other side, who cares if one enters instead of one time 10 times....

Orio.
Think you're smarty?

(Gone until 20 to November)

#7 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 28 April 2006 - 12:38 AM

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.


Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#8 Birdofprey

Birdofprey
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 28 April 2006 - 02:05 AM

[!--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) View Post[/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?


#9 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 28 April 2006 - 02:16 AM

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.
Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users