Jump to content

Strange MYSQL Counter Problem (Firefox vs. IE)


djcochran

Recommended Posts

I've created a simple hit counter on for my site, but I've noticed a strange problem. For some reason, it will increment correctly in IE, but in Firefox it sometimes goes up by 2. Why is it doing this??

 

<?php
// Connects to your Database
mysql_connect("localhost", "xxxxx", "xxxxx") or die(mysql_error());
mysql_select_db("student5") or die(mysql_error());

//Adds one to the counter
mysql_query("UPDATE counters SET num=num + 1 WHERE name='count'") or die("Update query failed: " . mysql_error());

//Retreives the current count
$query = "SELECT num FROM counters";
$result = mysql_query($query) or die("Select query failed: " . mysql_error());
$count = mysql_fetch_row(mysql_query("SELECT num FROM counters WHERE name='count'"));
?>

Because FF has a feature (bug) where it will request a page twice (wasting your bandwidth and submitting data twice) when it wants to apply the default character encoding that the user has set, despite the fact that it already has requested the page and should be able to use what it already has (lazy Mozilla programmers.)

 

You must use a session to detect and prevent duplicate page requests.

I originally found a post on the mozilla site that mentioned this (cannot find it now.) The feature has been present in a number of FF versions.

 

Upon just searching, there are apparently a number of different reasons (all outside of your control, which is why you must detect duplicate page requests on the server) why FF requests a page twice -

 

Firebug debugging,

empty src=".." urls,

applying default character encoding (that is either different than the page or when the page has none specified.)

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.