Home > Backend Development > PHP Tutorial > php购物车有关问题

php购物车有关问题

WBOY
Release: 2016-06-13 12:49:32
Original
994 people have browsed it

php购物车问题

<?php<br />
  include ('book_sc_fns.php');<br />
  // The shopping cart needs sessions, so start one<br />
  session_start();<br />
<br />
  @$new = $_GET['new'];<br />
<br />
  if($new) {<br />
    //new item selected<br />
    if(!isset($_SESSION['cart'])) {<br />
      $_SESSION['cart'] = array();<br />
      $_SESSION['items'] = 0;<br />
      $_SESSION['total_price'] ='0.00';<br />
    }<br />
<br />
    if(isset($_SESSION['cart'][$new])) {<br />
      $_SESSION['cart'][$new]++;<br />
    } else {<br />
      $_SESSION['cart'][$new] = 1;<br />
    }<br />
<br />
    $_SESSION['total_price'] = calculate_price($_SESSION['cart']);<br />
    $_SESSION['items'] = calculate_items($_SESSION['cart']);<br />
  }<br />
<br />
  if(isset($_POST['save'])) {<br />
    foreach ($_SESSION['cart'] as $isbn => $qty) {<br />
      if($_POST[$isbn] == '0') {<br />
        unset($_SESSION['cart'][$isbn]);<br />
      } else {<br />
        $_SESSION['cart'][$isbn] = $_POST[$isbn];<br />
      }<br />
    }<br />
<br />
    $_SESSION['total_price'] = calculate_price($_SESSION['cart']);<br />
    $_SESSION['items'] = calculate_items($_SESSION['cart']);<br />
  }<br />
<br />
  do_html_header("Your shopping cart");<br />
<br />
  if(($_SESSION['cart']) && (array_count_values($_SESSION['cart']))) {<br />
    display_cart($_SESSION['cart']);<br />
  } else {<br />
    echo "<p>There are no items in your cart</p><hr/>";<br />
  }<br />
<br />
  $target = "index.php";<br />
<br />
  // if we have just added an item to the cart, continue shopping in that category<br />
  if($new)   {<br />
    $details =  get_book_details($new);<br />
    if($details['catid']) {<br />
      $target = "show_cat.php?catid=".$details['catid'];<br />
    }<br />
  }<br />
  display_button($target, "continue-shopping", "Continue Shopping");<br />
<br />
  // use this if SSL is set up<br />
  // $path = $_SERVER['PHP_SELF'];<br />
  // $server = $_SERVER['SERVER_NAME'];<br />
  // $path = str_replace('show_cart.php', '', $path);<br />
  // display_button("https://".$server.$path."checkout.php",<br />
  //                 "go-to-checkout", "Go To Checkout");<br />
<br />
  // if no SSL use below code<br />
  display_button("checkout.php", "go-to-checkout", "Go To Checkout");<br />
<br />
  do_html_footer();<br />
?><br />
Copy after login


代码中的$_SESSION['cart'][$new]是什么意思,为什么要这样子做?

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template