مشکل با کلاس و کوکی بر روی هاست

ساخت وبلاگ

سلام دوستان من یه سایت نوشتم رو لوکال درست اجرا میشه اما وقتی رو هاست آپلود کردم تو قسمت اضافه کردن کالا به سبد خرید که با کوکی نوشتم ارور میده و اضافه نمی کنه
دوستان اگه میشه راهنمایی کنید ممنون میشم.

ارور:


Waing: Invalid argument supplied for foreach() in /home/srgirani/public_html/basket/product.cl.php on line 16
<?php
class Cart
{

//Add a product order to our COOKIE/JSON based cart.

public function AddProduct($productid, $quantity)
{
$x=0;
//Checks to see if cart already exists.

if (isset($_COOKIE['Cart']))
{
//JSON content is tued back into array.
$cart = json_decode($_COOKIE['Cart']);
foreach ($cart as $order => $product)
{
//Check to see if $products key ($order) matches the $products key we wish to remove.
if($product[0] == $productid)
{

//If result is false add product order to new array.
$record=$order;
$x=1;
}

}
if($x==1){

}else{
$cart[] = array($productid,$quantity);

//Encode cart array back into JSON.

$createcart = json_encode($cart);

setcookie('Cart',$createcart,time()+3600);
}
}
else
{
$cart = array();
$cart[] = array($productid,$quantity);

//Encode cart array back into JSON.

$createcart = json_encode($cart);

setcookie('Cart',$createcart,time()+3600);
}

//Add product id and quantity desired to cart.

}

//Displays our Cart to the page.

public function DisplayCart()
{

if (isset($_COOKIE['Cart']))
{

$cart = $_COOKIE['Cart'];

//JSON content is tued back into array.

$products = json_decode($cart);

//Loop through Cart array to display relevant Cart info.
//print_r($products);
foreach($products as $order => $product)
{
$myarr[]=$product[0];

//echo '<p>';
//echo $order;
//echo $product[0];
//echo $product[1];
//echo '</p>';
}
retu $myarr;
}
else
{
echo 'No Products In Cart';
}

}

//Remove product order from Cart.

public function RemoveProduct($orderid)
{

$cart = $_COOKIE['Cart'];

//JSON content is tued back into array.

$products = json_decode($cart);

$newcart = array();

foreach ($products as $order => $product)
{

//Check to see if $products key ($order) matches the $products key we wish to remove.
if($product[0] != $orderid)
{

//If result is false add product order to new array.

$newcart[] = array($product[0], $product[1]);

}

}

//Encode new Cart array into JSON.

$createcart = json_encode($newcart);

setcookie('Cart',$createcart,time()+3600);

}
public function CountCart()
{

if (isset($_COOKIE['Cart']))
{

$cart = $_COOKIE['Cart'];

//JSON content is tued back into array.

$products = json_decode($cart);

//count array.

$count=count($products);
retu $count;

}
else
{

retu '0';

}

}
}

?>

قمست اجرایی کد:

<?php
if(isset($_POST['addtobasket']) && !empty($_POST['addtobasket'])){
$id=clearxss($_POST['id']);
require_once('basket/product.cl.php');
$cart=new Cart();
$cart-> AddProduct($id,'1');
//echo "yes";

//header("Location: http://www.srgiran.com/index.php?srg=basket");
}

?>

برنامه نویس...
ما را در سایت برنامه نویس دنبال می کنید

برچسب : نویسنده : محمد رضا جوادیان programers بازدید : 85 تاريخ : دوشنبه 2 فروردين 1395 ساعت: 16:02