raymond_feliciano Posted November 29, 2011 Share Posted November 29, 2011 I recently created an application and tested on my local production environment. the problem I'm having is a cookie gets set with an a session variable. It works on my dev environment and I am able to view it's contents. When I uploaded the files to Network Solutions I receive get this error: Warning: Invalid argument supplied for foreach() in /data/18/1/27/121/1842447/user/1999590/htdocs/includes/session.php on line 55 and when I dump the variable it is empty. The version of php I am using is 5.3 and the version php Network Solutions is using is 5.1. Do you think it could be something with the two different versions of php or could it be a setting on their end. I am a novice php developer and I would appreciate any input thanks. Quote Link to comment Share on other sites More sharing options...
requinix Posted November 29, 2011 Share Posted November 29, 2011 What does your code look like? Quote Link to comment Share on other sites More sharing options...
xyph Posted November 29, 2011 Share Posted November 29, 2011 You could be getting this error on your local server as well. It all depends on how you have or haven't set up PHP's error reporting. Quote Link to comment Share on other sites More sharing options...
raymond_feliciano Posted November 29, 2011 Author Share Posted November 29, 2011 The code is long but this is what i use to set the cookie function AddToCart($subpid,$subtype,$subprice,$subcarving,$subline1,$subline2,$subpicture,$subdiscount_code){ global $mysql, $session, $form; $exist = false; $cart = ""; $i=0; if(!isset($_SESSION['cart']) || count($_SESSION['cart']) < 1){ $_SESSION['cart'] = array(0 => array("Product" => $subpid,                               "Layout" => $subtype,   "Price" => $subprice,   "Carving" => $subcarving,   "Line 1" => $subline1,   "Line 2" => $subline2,   "Quantity" => 1,   "Picture" => $subpicture,   "Discount Code" => $subdiscount_code)); } else{ foreach($_SESSION['cart'] as $item){ $i++; if($item['Product'] == $subpid && $item['Layout'] == $subtype && $item['Price'] == $subprice && $item['Carving'] == $subcarving && $item['Line 1'] == $subline1 && $item['Line 2'] == $subline2 && $item['Picture'] == $subpicture && $item['Discount Code'] == $item['Discount Code']){ array_splice($_SESSION['cart'], $i-1, 1, array(array("Product" => $subpid,                                         "Layout" => $subtype,                 "Price" => $subprice,                 "Carving" => $subcarving,                 "Line 1" => $subline1,                 "Line 2" => $subline2,                 "Quantity" => $item['Quantity'] + 1,                 "Picture" => $subpicture,                 "Discount Code" => $item['Discount Code']))); $exist = true; } } if($exist == false){ array_push($_SESSION['cart'], array("Product" => $subpid,                              "Layout" => $subtype,  "Price" => $subprice,  "Carving" => $subcarving,  "Line 1" => $subline1,  "Line 2" => $subline2,  "Quantity" => 1,  "Picture" => $subpicture,  "Discount Code" => $subdiscount_code)); } } setcookie("cart",serialize($_SESSION['cart']),time()+COOKIE_EXPIRE, COOKIE_PATH); return 0; } And here is a snippet my StartSession function which checks to see if the cookie is set if(!empty($_COOKIE['cart']) || $_COOKIE['cart'] != null){ $_SESSION['cart'] = array(); foreach(unserialize($_COOKIE['cart']) as $item){ array_push($_SESSION['cart'], array("Product" => $item['Product'],                                  "Layout" => $item['Layout'],  "Price" => $item['Price'],  "Carving" => $item['Carving'],  "Line 1" => $item['Line 1'],  "Line 2" => $item['Line 2'],  "Quantity" => $item['Quantity'],  "Picture" => $item['Picture'],  "Discount Code" => $item['Discount Code'])); } setcookie("cart",serialize($_SESSION['cart']),time()+COOKIE_EXPIRE, COOKIE_PATH); } The snippet from my StartSession function is where the error is thrown in the foreach loop. Again thanks for your help and sorry about the formatting. Quote Link to comment Share on other sites More sharing options...
raymond_feliciano Posted November 29, 2011 Author Share Posted November 29, 2011 On my local server I am able to actually view what's in the cookie when I dump the variable using var_dump() and I have it set to display all errors Quote Link to comment Share on other sites More sharing options...
raymond_feliciano Posted November 30, 2011 Author Share Posted November 30, 2011 I got it fixed by using stripslashes function. Again I'd lioke to thank everybody who attempted to help me out. Quote Link to comment 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.