欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

php购物车有关问题

程序员文章站 2022-06-17 15:30:27
...
php购物车问题
  include ('book_sc_fns.php');
// The shopping cart needs sessions, so start one
session_start();

@$new = $_GET['new'];

if($new) {
//new item selected
if(!isset($_SESSION['cart'])) {
$_SESSION['cart'] = array();
$_SESSION['items'] = 0;
$_SESSION['total_price'] ='0.00';
}

if(isset($_SESSION['cart'][$new])) {
$_SESSION['cart'][$new]++;
} else {
$_SESSION['cart'][$new] = 1;
}

$_SESSION['total_price'] = calculate_price($_SESSION['cart']);
$_SESSION['items'] = calculate_items($_SESSION['cart']);
}

if(isset($_POST['save'])) {
foreach ($_SESSION['cart'] as $isbn => $qty) {
if($_POST[$isbn] == '0') {
unset($_SESSION['cart'][$isbn]);
} else {
$_SESSION['cart'][$isbn] = $_POST[$isbn];
}
}

$_SESSION['total_price'] = calculate_price($_SESSION['cart']);
$_SESSION['items'] = calculate_items($_SESSION['cart']);
}

do_html_header("Your shopping cart");

if(($_SESSION['cart']) && (array_count_values($_SESSION['cart']))) {
display_cart($_SESSION['cart']);
} else {
echo "

There are no items in your cart


";
}

$target = "index.php";

// if we have just added an item to the cart, continue shopping in that category
if($new) {
$details = get_book_details($new);
if($details['catid']) {
$target = "show_cat.php?catid=".$details['catid'];
}
}
display_button($target, "continue-shopping", "Continue Shopping");

// use this if SSL is set up
// $path = $_SERVER['PHP_SELF'];
// $server = $_SERVER['SERVER_NAME'];
// $path = str_replace('show_cart.php', '', $path);
// display_button("https://".$server.$path."checkout.php",
// "go-to-checkout", "Go To Checkout");

// if no SSL use below code
display_button("checkout.php", "go-to-checkout", "Go To Checkout");

do_html_footer();
?>


代码中的$_SESSION['cart'][$new]是什么意思,为什么要这样子做?
php购物车有关问题

声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。

相关文章

相关视频