0

I have a page with a flash object on it, and I would like to count the pageviews by incrementing a field by 1 in my database.

The query works fine (tested it in phpMyAdmin) and the function gets executed only once, but still the field gets incremented by 2 every time I reload the page.

When I remove the flash object from the page, the field is incremented only by 1.

Can someone explain why this is the case, and how I can prevent this behaviour?

Thanks a lot!

PS: This guy seems to have the same problem, but no solution is posted... mysql wrong column increment

EDIT:

My logs show the following:

::1 - - [24/Aug/2013:13:42:16 +0200] "GET /page HTTP/1.1" 200 8008 "-" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.57 Safari/537.36"

::1 - - [24/Aug/2013:13:42:17 +0200] "GET /page HTTP/1.1" 200 8008 "http://localhost/page" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.57 Safari/537.36"
Community
  • 1
  • 1

1 Answers1

0

I am quite sure, the relevant page is loaded twice in many instances, which makes for two increments. A page loading twice is what happens in at least two cases:

  • My flash block extension, if I chose to activate flash
  • Some AV/SmartScreen or whatever, that preloads the page elsewhere to check it for Flash threats

Check your webserver logs to verify!

Eugen Rieck
  • 64,175
  • 10
  • 70
  • 92
  • Thanks for your response, I checked my logs and put them in the question description. Can you get more information out of them? I'm not aware of having a flash block extension or AV/Smartscreen software. – Tomas Mertens Aug 24 '13 at 11:48
  • Your log entries confirm this! You are requesting the same page twice, resulting in two counter increments. This is nothing you can "fix" from your PHP code, but you can "workaround" by e.g. setting a cookie with the last counter update timestamp, and if it exists and is very young skip the counter update. I recommend this for all web counters. – Eugen Rieck Aug 24 '13 at 12:19