PHP Shopping Cart Problem
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 is no items in your cart
";
}
$target = "index.php";
If we have just added a 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 the 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 ();
?>
What does the $_session[' cart ' [$new] in the code mean, and why do you do it this way?