Jump to content

Empty cookie after uploading to network solutions


raymond_feliciano

Recommended Posts

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.