Creating a counter
I would like to create a counter using php.
How would i find out if the user is a unique one? Store their ip address and compair the current user to the database? Also, how would i find out how long they visited a page for?
I think that's it for now.
Keith
Greg K posted this at 04:00 — 28th January 2005.
He has: 2,145 posts
Joined: Nov 2003
For a basic counter, store the IP address of last visitor wherever your store the count. Then compare the current IP with the last known. This work fairly well on sites not visited much. However, if two people are actively browsing pages that all use the same counter, as their hits alternate back and forth they will increase each time the other person was the last one to visit a page.
Off the top of my head, (I use counter/stat services, never wrote my own), I would say if you have a database, store each IP with the last timestamp. Then each visit check to see if the IP is in the list of all IP's. You would need something that clears the list once it gets so old, like run an hourly cron job that deletes any entries that are more than like 2 hours old.
Tracking how long someone has visited a page only works as long as they are staying on your site. I'm trying to think of the stats program I used once that tracked this. If I can find it, I'll post it here.
-Greg
Busy posted this at 08:09 — 28th January 2005.
He has: 6,151 posts
Joined: May 2001
for checking how long they stay at your site you have to use sessions or cookies, on a page you can't really get a true picture until they move to another page, but can get tricky as you first have to check they did come from another page on your site
Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.