如何获取帖子被查看的次数?
所以我正在使用 cakePHP 制作一个应用程序。
我想知道是否有人知道如何获取论坛上的帖子获得的唯一浏览次数。
换句话说。假设我在论坛上发帖。当有人查看我的帖子时,他应该只能添加一次查看次数。
我不确定 cakePHP 是否有内置的东西可以帮助解决这个问题,因为我对它还很陌生。
如果没有,自定义解决方案不是问题,但如果有人可以引导我走向正确的方向。就像如何完成这种性质的事情一样。我已经使用用户的 IP 地址完成此操作,并将其存储在每天刷新的数据库中,但可能有更好的解决方案。请告诉我。
感谢您抽出时间。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我会将每个帖子的每次浏览记录在一个表中,其中包含访问者的 IP、时间和时间。查看日期。
然后,您可以进行查询来计算每个帖子和每天的唯一 IP。它将为您提供每天的独特观看次数。
如果您希望更彻底,您还可以存储用户代理信息并过滤掉搜索引擎爬虫(Google、bing 等)。
这里有一个包含完整可用代码的方便教程:CakePHP 的点击计数行为
我在这里发现了一些关于独特访问量和访客的有趣见解。
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.