test
test

Reputation: 18200

An efficient way of counting views?

You know how some websites have counters or "views" for their multimedia stuff? What's an efficient way, using PHP (and/or jQuery!), of counting views per said page such as page.php?id=2?

I don't want to do it the traditionally way because then anyone can just refresh the browser over and over and over...

Upvotes: 0

Views: 143

Answers (2)

Chris Sobolewski
Chris Sobolewski

Reputation: 12935

You will need somewhere to store the data. This could be a flat file, a CSV, or a database.

Just make an entry in to your storage method of choice, and then put a cookie in their browser.

Upvotes: 0

Mark Grey
Mark Grey

Reputation: 10257

There isn't a hard and fast way to ensure you are counting unique visitors, but you can save a list of remote addresses to a database and only count individual IP's once (or save and increment their individual views.) This can be accomplished using the $_SERVER['REMOTE_ADDR'] key in the server superglobal. This isn't true unique visitors for obvious reasons (dynamic IPs, proxy connections etc) but it is close enough for general public use.

Upvotes: 2

Related Questions