Jump to content

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.)

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.