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?
The the site: the site has over 10k+ posts, im not sure, if this done with a cookie would work :)
An开发者_运维百科d about updating the DB, should i do it in realtime with update low priority, or saving the data and processing like every 5 mins?
Gimma please some input how i can make this. Thank you
Take the unique user by comparing ip | session Id | page Id if the combination of same value exists then don`t insert it or insert it but process later by taking unique values
You can work it with the cookie, like setting a cookie var UPDATED to 1 if the hit have been updated.
But the problem with COOKIE is anyone can edit it, so you can also try it with SESSION as user can not edit it.
DB is not a good option i think, You can try Google Analytic too
Another answer, suggested from Page View Counter like on StackOverFlow, is to
- add a 'token resource' in your page header, such as
<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). This avoids the need for cookies or storing [ip | session | page] for each pageview, cutting down on the number of database requests; and avoids the need for cookies.
It is just as safe as an [ip | session | page] combination agains attack (in either case, someone can write a tight loop requesting the resource-or-page without storing cookies). 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).
精彩评论