Re: count clicks to count most important news

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 1 Jan 2012, at 16:26, muad shibani wrote:

> I have a website that posts the most important news according to the number
> of clicks to that news
> the question is : what is the best  way to prevent multiple clicks from the
> same visitor?

I'm assuming this is not a voting system, and the news items you're counting are sourced from your own site and, with all due respect to Ash, unlikely to be a target for false clicks. All you're really wanting to do is prevent the site from registering multiple hits from the same user in a short period of time.

I would probably use memcached on the server-side to store short-term information about clicks. When a news item is loaded...

1) Construct the memcache key: "newsclick_<article_id>_<ip_address>".
2) Fetch the key from memcache.
3a) If it does not exist, log the hit.
3b) If it does exist, compare time() with the value and only log the hit if time() is greater.
4) Store the key with a value of time() + 300 and an expiry of the same value.

This will prevent hits being logged for the same news item from the same IP address within 5 minutes of other hits.

Other alternatives would be to use cookies (could get messy, and not very reliable since it requires the response from click 1 to be processed before click 2 gets started), Javascript (as suggested by tedd but without the token - it would work pretty well and would be a lot easier to implement than the above, but you sacrifice having full control over it).

If I'm interpreting the requirement correctly my solution is almost certainly overkill, and a simple Javascript solution would be more than sufficient.

-Stuart

-- 
Stuart Dallas
3ft9 Ltd
http://3ft9.com/
-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux