Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

I want to know how sites like stackoverflow.com or imgur.com manage the page views of their article. i.e. once i view it and then no matter how many times i refresh it.. the page view count won't increase. I would also like to implement it for my image site and would also like to know when should i update views in database.

Thanks.

share|improve this question
add comment

2 Answers 2

up vote 3 down vote accepted

This is normally handled using session variables. When the user enters the site for the first time, a session is created.

Every time you view view an article or a page, the site checks whether the id of the page is stored in the session variable. If it isn't, then the view is counted and the id stored in the session variable. Otherwise, the view count is skipped.

The way you implement this feature depends on the programming language you used to create your site (Ruby, Python, Java, PHP...).

share|improve this answer
    
Do sites really store every page you visit in a session variable? That's a lot of overhead to send to the server on every page request, if a user has visited lots of pages. –  DisgruntledGoat Nov 3 '11 at 20:33
    
You don't need to store every page, but just the ID corresponding to the question record. Also, session variables usually are stored on the server, you just pass the session_id between the client and the server. –  Simone Carletti Nov 3 '11 at 23:09
    
Ah OK, I was getting mixed up with cookies. And thinking about it, storing 100+ question IDs should be less than 1KB. –  DisgruntledGoat Nov 3 '11 at 23:19
add comment

Here's how I would do it:

  1. First check that it looks like a real person using a browser and not a search engine bot (e.g. check the user agent string for "bot").
  2. Store the IP address in a database with each visited page, for up to 24 hours.
  3. On each page load, if this IP address has not viewed this page in the last 24 hours then add 1 to the view count.
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.