【发布时间】:2015-06-26 21:29:41
【问题描述】:
我创建了一个结帐系统。每当有人提交订单时,我会将他们带到另一个页面,感谢他们的订单,并简要介绍他们所订购的内容。它被称为 orderconfirmation.php。在该页面中,我有一个未设置的会话脚本,用于停止购物车会话。唯一的问题是,会话不会在页面加载时停止。我可以说出来,因为我在每个页面上的购物车数量计数器仍然显示购物车中的物品。他们必须离开该页面才能让未设置的脚本离开。在有人为他们的订单付款并且仍然看到之后,他们变得有点困惑,所以当页面转到 orderconfirmation.php 页面时,我需要结束购物车会话。
这是我在 orderconfirmation.php 页面上取消设置会话的代码:
//Initialize shopping cart session
if(!isset($_SESSION['shopping_cart'])) {
$_SESSION['shopping_cart'] = array();
}
// Empty cart
unset($_SESSION['shopping_cart']);
在加载此页面时,我可以采取另一种方法来取消会话吗?
购物车数量计数器
//Shopping Cart Quantity Count
if(isset($_SESSION['shopping_cart']) && is_array($_SESSION['shopping_cart'])) {
$totalquantity = 0;
foreach($_SESSION['shopping_cart'] AS $product) {
$totalquantity = $totalquantity + $product['quantity'];
}
}
else {
$totalquantity = 0;
}
【问题讨论】: