Jump to content

Check how many times an article is viewed?


Mr Chris

Recommended Posts

Hello,

 

I have a counter on my page which increments a column in my database every time a story on my site is viewed:

 

$result = mysql_query("SELECT * FROM stories WHERE story_id=".$id);
  $row = mysql_fetch_array($result);
  $i = $row['my_count'];
  $i++;
  $query = "UPDATE stories SET read_count = '$i' WHERE story_id=".$id;
  $result = mysql_query($query);

 

Is there anyway I could make it a bit better to not allow for things like a user sitting there and hitting refresh 15 times, and bots visiting the page, things like that really?

 

Thanks

You can use sessions to ensure they are only counted once.  Not sure about the bots issue.  For crawlers, which I'm not even sure if they would be counted, you would have to conditionally detect them.  Try Google, something like: Detect Crawlers.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.