ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL); require_once __DIR__ . '/includes/cart.php'; $uri = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH); $uri = rtrim($uri, '/') ?: '/'; // Remove base path if project is in a subdirectory $scriptDir = dirname($_SERVER['SCRIPT_NAME']); if ($scriptDir !== '/' && strpos($uri, $scriptDir) === 0) { $uri = substr($uri, strlen($scriptDir)); } $uri = rtrim($uri, '/') ?: '/'; // Handle cart actions if ($_SERVER['REQUEST_METHOD'] === 'POST' && $uri === '/cart/add') { $product_id = $_POST['product_id'] ?? ''; $qty = (int)($_POST['qty'] ?? 1); if ($product_id) { cart_add($product_id, $qty); } header('Location: ' . script_base() . '/cart'); exit; } if ($uri === '/cart/update') { $id = $_GET['id'] ?? ''; $qty = (int)($_GET['qty'] ?? 1); if ($id) { cart_update($id, $qty); } header('Location: ' . script_base() . '/cart'); exit; } if ($uri === '/cart/remove') { $id = $_GET['id'] ?? ''; if ($id) { cart_remove($id); } header('Location: ' . script_base() . '/cart'); exit; } // Route to pages $routes = [ '/' => ['file' => 'pages/home.php', 'params' => []], '/shop' => ['file' => 'pages/shop.php', 'params' => []], '/collections' => ['file' => 'pages/collections.php', 'params' => []], '/about' => ['file' => 'pages/about.php', 'params' => []], '/contact' => ['file' => 'pages/contact.php', 'params' => []], '/returns-exchanges' => ['file' => 'pages/returns.php', 'params' => []], '/cart' => ['file' => 'pages/cart.php', 'params' => []], '/checkout' => ['file' => 'pages/checkout.php', 'params' => []], ]; // Dynamic routes if (preg_match('#^/product/(.+)$#', $uri, $matches)) { $route_params = ['slug' => $matches[1]]; include __DIR__ . '/pages/product.php'; exit; } if (preg_match('#^/collection/(.+)$#', $uri, $matches)) { $route_params = ['slug' => $matches[1]]; include __DIR__ . '/pages/collection_detail.php'; exit; } if (isset($routes[$uri])) { $route_params = $routes[$uri]['params']; include __DIR__ . '/' . $routes[$uri]['file']; exit; } // 404 http_response_code(404); require_once __DIR__ . '/includes/header.php'; echo '

404 - Page Not Found

The page you are looking for does not exist.

Back to Home
'; require_once __DIR__ . '/includes/footer.php'; function script_base() { $dir = dirname($_SERVER['SCRIPT_NAME']); return $dir === '/' ? '' : $dir; }