hit counter

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
tobie montana
Forum Newbie
Posts: 1
Joined: Sat Jul 31, 2010 8:34 am

hit counter

Post by tobie montana »

Heya, i wonder if someone could help me make a kind of advanced hit counter, It should only count a visit from 1 computer each 24/h so if i visit the site several times with my computer 1 day it will only count 1 time that day. Then if you are the 100th visitor you should come to another site. Thanks in advance // Tobie Montana
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: hit counter

Post by califdon »

tobie montana wrote:Heya, i wonder if someone could help me make a kind of advanced hit counter, It should only count a visit from 1 computer each 24/h so if i visit the site several times with my computer 1 day it will only count 1 time that day. Then if you are the 100th visitor you should come to another site. Thanks in advance // Tobie Montana
What kind of help are you asking for? If you want someone to write it for you, good luck. If you just want some tips about the logic, maybe I can help. Where do you want to store the visits, in cookies on the visitor's computer or in a database on the server? Each has its own advantages and disadvantages. If you want to use cookies, the logic would be something like this:

Code: Select all

Is there a cookie on the user's computer? If no, this is visit #1, set cookie; if yes, is the cookie date today's date? If no, increment the visit count, store back to cookie; if yes, ignore.
If this is visit #100, do whatever.
If you want to use a database, the logic would be something like:

Code: Select all

Query your database: is there a record for this user (or IP address)? If no, this is visit #1, insert record; if yes, is the date today's date? if no, increment the visit count, update record; if yes, ignore.
If this is visit #100, do whatever.
Post Reply