I have two hosting accounts. On one, my setcookie script works fine; cookies are created. On the other, the same script doesn't work. The function returns TRUE, but no cookies is created.
I checked to make sure that the variables have values and that the proper expire time is set and etc.
Any ideas?
I checked to make sure that the variables have values and that the proper expire time is set and etc.
Any ideas?
Code:
<?php
foreach($_POST as $name => $value){
if($name == 'hItem'){
$item = $value;
}
else if($name == 'hPrice'){
$price = $value;
}
else if($name == 'hQuantity'){
$quantity = $value;
}
else if($name == 'wQuantity'){
$wantedQuantity = $value;
}
else if($name == 'hImage'){
$image = $value;
}
else if($name == 'hShipping'){
$shipping = $value;
}
else if($name == 'hCategory'){
$category = $value;
}
}
if($quantity <= 0){
echo "This item is no longer available. Please select another item!";
}
else{
if($wantedQuantity > $quantity){
$wantedQuantity = $quantity;
}
$i = 0;
while($i < 1000){
if(isset($_COOKIE['cItem' . $i])){
if($_COOKIE['cItem' . $i] == $item){
break;
}
}
else
break;
$i++;
}
setcookie("cItem" . $i, $item, time() + 3600);
setcookie("cPrice" . $i, $price, time() + 3600);
setcookie("cQuantity" . $i, $wantedQuantity, time() + 3600);
setcookie("cImage" . $i, $image, time() + 3600);
setcookie("cShipping" . $i, $shipping, time() + 3600);
setcookie("cCategory" . $i, $category, time() + 3600);
$link ="<script>document.location.href = 'viewcart_t.php'</script>";
echo $link;
}
?>
Comment