輸入一些變量之後,添加變量數組到Cookie,則得到錯誤
PHP代碼:
$CartItem = array(
'itemID' => $itemID,
'ProductName' => $ProductName,
'Option' => $Option,
'Quantity' => $Quantity,
'Price' => $Price,
'Total' => $Total
);
setcookie('CartItem', $CartItem, null);
輸出錯誤:
Warning: setcookie() expects parameter 2 to be string, array given in /Users/user/Sites/app/addtocart.php on line 46
你真的不應該爲此使用cookies。而應將購物車存放在'$ _SESSION'中,如果需要長期存儲,請將其序列化爲數據庫。有關示例,請參閱http://stackoverflow.com/questions/8128433/removing-values-from-php-session/8128472#8128472。 – 2012-02-15 14:23:54