Page 2 of 2
Re: Super frustrating: row inserts twice
Posted: Thu Jun 18, 2009 5:55 am
by mattpointblank
Okay, I made a cut down version, completely stripped down, no reliance on any other files, and it still runs twice:
index.php:
Code: Select all
<a href="clickme.php?id=123">click here</a>
clickme.php
Code: Select all
<?php
$message = $_GET['id'];
$headers = "From: me@site.com";
mail("me@site.com", "test", $message, $headers);
header("Location: index.php");
?>
I get two emails when I click the link. Can someone else verify that this happens with them too?
EDIT: Just saw this:
http://informationideas.com/news/2006/1 ... hpfirefox/ - it seems that in IE, this doesn't happen anymore. It was happening earlier when I tested, but now it seems that both my shopping cart code and the above stripped-down code only runs once in IE6. Now we're getting somewhere!
EDIT 2: Pickle was right - Firebug is the culprit!
http://groups.google.com/group/firebug/ ... e41de7f494
It definitely seemed to be happening in IE the other day though.
Re: Super frustrating: row inserts twice
Posted: Thu Jun 18, 2009 10:34 am
by mattpointblank
Apologies for all the posts in a row by me, but I'm still having issues.
Now I know it's Firebug, I'm trying to code around it. I know the majority of my users won't have it installed so I could just disable it and get on with coding, but it's a worrying issue for a webstore, so I need to fix it.
I've tried setting a session variable once the INSERT query has run, and only running that query if the session variable doesn't exist. To allow users to add more than one product to their basket, I unset the session variable once the header() redirect is complete and they reach shoppingcart.php. It seems though that Firebug repeats the request to additem.php once shoppingcart.php (or whatever page the user is sent to after additem.php) has completely finished loading - this means that I still get two rows inserted. I'm a bit lost in the logic of all of this - can anyone see a foolproof way for me to prevent my page from being inserted twice?
Matt
Re: Super frustrating: row inserts twice
Posted: Thu Jun 18, 2009 11:30 am
by pickle
Now that we know it's Firebug, I'm not sure you should loose much sleep over this.
Firebug duplicates the request so it can "harvest" the response. This only happens if the user has turned on the "Net" portion (or perhaps the "Console" or "Script" portion) of Firebug for your particular store - something that is disabled by default. You're right that the vast majority of your users won't have Firebug installed. An even larger majority won't have explicitely told Firebug to run on your site. Those that have - well - they should know what they're getting into.
I can't think of a guaranteed way to stop Firebug requests without the potential for stopping a legitimate occurrence of a quick double post. Maybe if Firebug sends something unique to it along with the request? Maybe $_POST['thisRequestIsComingFromFirebug']? I'm just guessing - I've never heard of anything like that.
If it was me, I'd wouldn't worry about it.
Re: Super frustrating: row inserts twice
Posted: Fri Jun 19, 2009 3:17 am
by mattpointblank
I filed a bug report with Firebug, I guess all I can do is wait. I did consider that less than 1% of my viewers would be affected, but it stills bugs me that even 0.5% of my shoppers could accidentally double their orders! Oh well...
Re: Super frustrating: row inserts twice
Posted: Fri Jun 19, 2009 7:20 pm
by Tobey
Another solution would be to allow every item to be in the basked only one time, so additem.php would not do anything if the entry does already exist. If an item is already in the basket, you can send the user to changebasket.php or something like that, which changes the quantity of an item. This might happen twice, if the problem with Firebug still occurs, but it would not have a real impact on the user's order, like having too many items in the basket.
Re: Super frustrating: row inserts twice
Posted: Sat Jun 20, 2009 12:02 am
by Eric!
If you really want to go hardcore into this, install web scarab to monitor your http traffic to see what firebug is doing and if there are any tags posted for detecting firebug on the server side.