سؤال

So I am making an application using cakePHP.

I am wondering if anyone knows how to get the number of unique views a post on a forums gets.

So in other words. Say I post to a forum. When somebody views my post, he should only be able to add to the # of views once.

I am not sure if cakePHP has anything built in that might be able to help with this as I am fairly new to it.

If not, a custom solution isn't a problem, but if someone could guide me in the right direction. As in how something of this nature can be accomplished. I have done this using the IP address of the user and storing it in a database which gets flushed daily but there might be a better solution. Please let me know.

Thanks for your time.

هل كانت مفيدة؟

المحلول

I would log every view of each post in a table with the visitor's IP and time & date of the view.

You could then make a query to count the unique IPs per post and day. It would give you the number of unique views per day.

If you are looking to be thorough, you could also store user-agent information and filter out search engine crawlers (Google, bing, etc.).

A handy tutorial with complete usable code here: hitcount behavior for CakePHP

I found here a few interesting insights about Unique Visits and Visitors.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top