djcochran Posted April 11, 2009 Share Posted April 11, 2009 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'")); ?> Quote Link to comment https://forums.phpfreaks.com/topic/153652-strange-mysql-counter-problem-firefox-vs-ie/ Share on other sites More sharing options...
PFMaBiSmAd Posted April 11, 2009 Share Posted April 11, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/153652-strange-mysql-counter-problem-firefox-vs-ie/#findComment-807415 Share on other sites More sharing options...
.josh Posted April 11, 2009 Share Posted April 11, 2009 has the universe been turned upside down? That sounds like something IE would be guilty of. Quote Link to comment https://forums.phpfreaks.com/topic/153652-strange-mysql-counter-problem-firefox-vs-ie/#findComment-807418 Share on other sites More sharing options...
jackpf Posted April 11, 2009 Share Posted April 11, 2009 Wow, I never knew that. Does this still occur when you have default UTF-8 encoding do you know? Quote Link to comment https://forums.phpfreaks.com/topic/153652-strange-mysql-counter-problem-firefox-vs-ie/#findComment-807419 Share on other sites More sharing options...
PFMaBiSmAd Posted April 11, 2009 Share Posted April 11, 2009 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.) Quote Link to comment https://forums.phpfreaks.com/topic/153652-strange-mysql-counter-problem-firefox-vs-ie/#findComment-807455 Share on other sites More sharing options...
PFMaBiSmAd Posted April 11, 2009 Share Posted April 11, 2009 Found the thread - http://www.phpfreaks.com/forums/index.php/topic,216715.msg992061.html#msg992061 Quote Link to comment https://forums.phpfreaks.com/topic/153652-strange-mysql-counter-problem-firefox-vs-ie/#findComment-807462 Share on other sites More sharing options...
jackpf Posted April 11, 2009 Share Posted April 11, 2009 Oooh right, it's only when you don't have a char set defined. Oh well, I have one anyway so that's ok. Quote Link to comment https://forums.phpfreaks.com/topic/153652-strange-mysql-counter-problem-firefox-vs-ie/#findComment-807496 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.