Birdofprey Posted April 26, 2006 Share Posted April 26, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/8505-hit-counter/ Share on other sites More sharing options...
DepretioN Posted April 26, 2006 Share Posted April 26, 2006 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 Link to comment https://forums.phpfreaks.com/topic/8505-hit-counter/#findComment-31131 Share on other sites More sharing options...
Birdofprey Posted April 26, 2006 Author Share Posted April 26, 2006 [!--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. Quote Link to comment https://forums.phpfreaks.com/topic/8505-hit-counter/#findComment-31151 Share on other sites More sharing options...
.josh Posted April 27, 2006 Share Posted April 27, 2006 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 Link to comment https://forums.phpfreaks.com/topic/8505-hit-counter/#findComment-31217 Share on other sites More sharing options...
Birdofprey Posted April 27, 2006 Author Share Posted April 27, 2006 [!--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? Quote Link to comment https://forums.phpfreaks.com/topic/8505-hit-counter/#findComment-31318 Share on other sites More sharing options...
Orio Posted April 27, 2006 Share Posted April 27, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/8505-hit-counter/#findComment-31375 Share on other sites More sharing options...
.josh Posted April 28, 2006 Share Posted April 28, 2006 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 Link to comment https://forums.phpfreaks.com/topic/8505-hit-counter/#findComment-31501 Share on other sites More sharing options...
Birdofprey Posted April 28, 2006 Author Share Posted April 28, 2006 [!--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? Quote Link to comment https://forums.phpfreaks.com/topic/8505-hit-counter/#findComment-31529 Share on other sites More sharing options...
.josh Posted April 28, 2006 Share Posted April 28, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/8505-hit-counter/#findComment-31533 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.