I have looked at different ways to approach this but I would like a method which does not allow people to get around it. Just need a simple, light-weight method to count the number of views off different news articles which are stored in a database:
id | title | body | date | views
1 Stack Overflow 2010-01-01 23
- Session
– Could they not just clear browser data and reload page for another view? Any way to stop this? - Database table of ip addresses
– Tons of entries, may hinder performance - Log file
– Same issue as database however I’ve seen lots of examples
For a performance critical system and for ensuring accuracy, which method should I look into further?
Thanks.
If you’re looking to figure out how many unique visitors you have to a given page, then you need to keep information that is unique to each visitor somewhere in your application to reference.
IP addresses are definitely the “safest” way to go, as a user would have to jump through a good many hoops to manually change their IP address. That being said you would have to store a pretty massive amount of data if this is a commercial web-site for each and every page.
What is more reasonable to do is to store the information in a cookie on the client’s machine. Sure if your client doesn’t allow cookies you will have a skewed number and sure the user can wipe their browser history and you will have a skewed number but overall your number should be relatively accurate.
You could potentially keep this information cached or in session-level variables, but then if your application crashes or restarts you’re SOL.
If you REALLY need to have nearly 100% accurate numbers then your best bet is to log the IP addresses of each page’s unique visitors. This will ensure you the most accurate count. This is pretty extreme though and if you can take a ~5+% hit in accuracy then I would definitely go for the cookies.