简体   繁体   English

保留唯一文章查看次数记录的最有效方法是什么

[英]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.

相关问题 在图像上实现视图数量的有效方法-PHP - Effective way to implement the number of views on images - PHP 在Laravel中从数据库转换字符串名称的最有效方法是什么 - What is the most effective way to translate string names from database in Laravel 在 PHP/MySQL 应用程序中管理时区的最有效方法是什么? - What is the most effective way to manage time zones in a PHP/MySQL application? Doctrine ODM-查询具有最多视图的文章 - Doctrine ODM - query for an article with the most views 从中匹配数据的最有效方法是什么 <table > 用PHP? - What's the most effective way to match out data from <table > with PHP? 显示帖子评论的最有效方法 - Most Effective way to display comments for a post 使用多种自然语言最有效的方式 - Most effective way working with multiple natural languages 从多对多表中选择所有数据的最有效方法是什么? - What is the most effective way to select all data from many-to-many table? 将AdWords信息同步到本地数据库的最经济有效的方法是什么 - What is the most cost-effective way of synchronising Adwords information to local database Laravel 4.2中保护视图的最有效方法? - Most effective way of protecting a view in Laravel 4.2?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM