PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
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!
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?
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.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
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...
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.
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.