简体   繁体   English

页面浏览/帖子浏览计数器

[英]Page View / Post View Counter

I'm trying to make a post view counter, so far its easy, but i have following problem, when user reloads the page it gets updated again, i want track only raw, but not the reloads.我正在尝试制作一个帖子视图计数器,到目前为止它很容易,但是我有以下问题,当用户重新加载页面时它会再次更新,我只想跟踪原始内容,而不是重新加载。 How i could make this best?我怎样才能做到最好? setting a cookie?设置一个cookie?

The the site: the site has over 10k+ posts, im not sure, if this done with a cookie would work:)该站点:该站点有超过 10k+ 个帖子,我不确定,如果使用 cookie 完成此操作是否可行:)

And about updating the DB, should i do it in realtime with update low priority, or saving the data and processing like every 5 mins?关于更新数据库,我应该以更新低优先级实时进行,还是像每 5 分钟一样保存数据和处理?

Gimma please some input how i can make this. Gimma 请输入我如何做到这一点。 Thank you谢谢

You can work it with the cookie, like setting a cookie var UPDATED to 1 if the hit have been updated.您可以使用 cookie,例如如果命中已更新,则将 cookie var UPDATED 设置为 1。
But the problem with COOKIE is anyone can edit it, so you can also try it with SESSION as user can not edit it.但是 COOKIE 的问题是任何人都可以编辑它,所以你也可以用 SESSION 尝试它,因为用户无法编辑它。
DB is not a good option i think, You can try Google Analytic too我认为 DB 不是一个好选择,您也可以尝试 Google Analytic

Take the unique user by comparing ip |通过比较 ip 来获取唯一用户 | session Id | session 标识 | page Id if the combination of same value exists then don`t insert it or insert it but process later by taking unique values如果存在相同值的组合,则页面 ID 不插入或插入,但稍后通过获取唯一值进行处理

Another answer, suggested from Page View Counter like on StackOverFlow , is to另一个答案, 如 StackOverFlow 上的 Page View Counter建议的,是

  • add a 'token resource' in your page header, such as <link href="/questions/246919/increment-view-count" type="text/css" rel="stylesheet" /> .在您的页面 header 中添加“令牌资源”,例如<link href="/questions/246919/increment-view-count" type="text/css" rel="stylesheet" /> Notice that the token resource should be page-specific (due to path), and that all modern browsers cache the resource files that they download.请注意,令牌资源应该是特定于页面的(由于路径),并且所有现代浏览器都会缓存它们下载的资源文件。
  • only increment your counter when the token resource is downloaded anew (you can use apache's mod-rewrite to keep tidy urls that then map to whatever incrementing counter you have).仅在重新下载令牌资源时才增加您的计数器(您可以使用 apache 的 mod-rewrite 来保持整洁的 url,然后 map 到您拥有的任何递增计数器)。 This avoids the need for cookies or storing [ip |这避免了对 cookies 或存储 [ip | session | session | page] for each pageview, cutting down on the number of database requests; page] 为每个页面浏览量,减少数据库请求的数量; and avoids the need for cookies.并避免了对 cookies 的需要。

It is just as safe as an [ip |它与 [ip | session | session | page] combination agains attack (in either case, someone can write a tight loop requesting the resource-or-page without storing cookies). page] 组合对抗攻击(在任何一种情况下,有人可以编写一个紧密循环来请求资源或页面而不存储 cookie)。 But there is no safe-fail way to avoid abuse while counting all requests (because of NAT, you can not rely on unique IPs for everyone).但是在计算所有请求时没有安全失败的方法来避免滥用(因为 NAT,您不能依赖每个人的唯一 IP)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM