Jump to content

Recommended Posts

I'm in the very early stages of making building a shopping cart. The problem is when I add a product to my cart in firefox it add's two of them instead of one but it works fine in IE. I can't figure out what the problem is. Here is the code.

 

function RequestClean($object) {
  $object = htmlentities(trim(addslashes($_REQUEST["$object"])));
  return $object;
}
function AddTo() {
  $ModelNum = RequestClean("ModelNum");
  $Glass = RequestClean("Glass");
  $Metal = RequestClean("Metal");
  $Quantity = RequestClean("Quantity");
  if($ModelNum AND $Glass AND $Metal AND $Quantity) {
    $_SESSION["Cart"][] = array("ModelNum"=>"$ModelNum", "Glass"=>"$Glass", "Metal"=>"$Metal", "Quantity"=>$Quantity);
  }
}


if(IsSet($_REQUEST["AddTo"])) {
  AddTo();
} elseif(IsSet($_REQUEST["ClearCart"])) {
  session_destroy();
  $_SESSION["Cart"] = "";
}

Link to comment
https://forums.phpfreaks.com/topic/133422-_session-gets-added-twice-in-firefox/
Share on other sites

FF will request a page a second time to apply its' default character encoding when it cannot figure out the character set encoding being used on a page or the page has none specified. Firefox considers this to be a feature, I would call it a bug (FF already has the page, why request it again.)

 

The best solution would be to set a session variable that says that the form processing code has executed once and then check this variable at the start of your code and skip the form processing for all the requests after the first one.

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.