<?php // Include the header file (assumed to contain common HTML and styles) include('includes/header.php'); ?>
<?php session_start();
class Product { private $productId; private $productName; private $price;
public function __construct( $productId, $productName, $price ) { $this->productId = $productId; $this->productName = $productName; $this->price = $price; }
public function getId() { return $this->productId; }
public function getName() { return $this->productName; }
public function getPrice() { return $this->price; }
}
$products = array ( 1 => new Product( 1, "SuperWidget", 19.99 ), 2 => new Product( 2, "MegaWidget", 29.99 ), 3 => new Product( 3, "WonderWidget", 39.99 ) );
if ( !isset( $_SESSION["cart"] ) ) $_SESSION["cart"] = array();
if ( isset( $_GET["action"] ) and $_GET["action"] == "addItem" ) { addItem(); } elseif ( isset( $_GET["action"] ) and $_GET["action"] == "removeItem" ) { removeItem(); } else { displayCart(); }
function addItem() { global $products; if ( isset( $_GET["productId"] ) and $_GET["productId"] >= 1 and $_GET["productId"] <= 3 ) { $productId = (int) $_GET["productId"];
function removeItem() { global $products; if ( isset( $_GET["productId"] ) and $_GET["productId"] >= 1 and $_GET["productId"] <= 3 ) { $productId = (int) $_GET["productId"];