[英]what is the most effective way to keep records of number of uniqie article views
I am trying to create an article based website using codeigniter. 我正在尝试使用codeigniter创建基于文章的网站。 When any article is requested to fetch from database for viewing, I use the following code to mark the number of unique view of each article in a separate table called "hits". 当请求从数据库中获取任何文章进行查看时,我使用以下代码在称为“ hits”的单独表中标记每篇文章的唯一视图数。
mysql_query("INSERT INTO hits(ip,article_slug,hitcount)
VALUES('$ip_address','$id',1)
ON DUPLICATE KEY UPDATE hitcount=hitcount+0");
I take the IP address of the user and get the value of article_slug from $this->uri->segment(3); 我获取用户的IP地址,并从$ this-> uri-> segment(3)获取article_slug的值; and then run the above mysql query. 然后运行上面的mysql查询。
I am using the IP address here to get the number of unique views, but it suddenly occurs to me that several people could be using the same IP address. 我在这里使用IP地址来获取唯一视图的数量,但是我突然想到几个人可能正在使用相同的IP地址。 So in that case my query above doesn't seem effective. 因此,在这种情况下,我上面的查询似乎无效。
So I was wondering what is the most effective way to do it. 所以我想知道什么是最有效的方法。 One of my friends was talking about doing it using cookies instead of IP address. 我的一个朋友正在谈论使用Cookie而不是IP地址来实现。 Do you think its a good idea or there is a better way of doing it? 您认为这是一个好主意还是有更好的方法呢?
Could you please give me an idea on how to do this? 您能给我一个关于如何做到这一点的想法吗?
Thanks in Advance :) 提前致谢 :)
I would recommend using Google Analytics and setting up a Custom Report that tracks only article views. 我建议使用Google Analytics(分析)并设置仅跟踪文章浏览量的自定义报告。 This would give you the insights you seek plus a lot more and it would avoid counting bots (like Google, Bing or a SPAMer). 这将为您提供所寻求的见解以及更多信息,并且避免计算机器人(例如Google,Bing或SPAMer)。
But if you defiantly want to track users on your own I would recommend tracking the IP address in one field and Session ID in another. 但是,如果您绝对想自己跟踪用户,我建议您在一个字段中跟踪IP地址,在另一个字段中跟踪会话ID。
session_start();
$user['ip'] = $_SERVER['REMOTE_ADDR'];
$user['sid'] = session_id();
The reason behind using cookie is that if some group of user is behind proxy you will get same ip-address for all the user who read your article which is wrong. 使用Cookie的原因是,如果某些用户组位于代理之后,则对于阅读您的文章的所有用户,您将获得相同的IP地址,这是错误的。
So you can use combo of both and that way you could get better results. 因此,您可以同时使用两者的组合,这样可以获得更好的结果。 You can either use cookie or session. 您可以使用cookie或会话。 But if you use cookie and give it an expiry period of about a year or more and if you specify some unique hash to the cookie (which could be md5 of the log table's primary key) and then you can track users pretty well. 但是,如果您使用cookie并赋予它大约一年或更长时间的有效期限,并且为cookie指定了一些唯一的哈希值(可能是日志表主键的md5),那么您可以很好地跟踪用户。
let me know if you do not understand what I mean. 如果您不明白我的意思,请告诉我。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.