<?php
// add_to_cart.php - Handle adding to cart and redirect back
session_start();
include_once 'config.php';
include_once 'auth.php';

if (isset($_GET['product_id']) && isset($_GET['return_url'])) {
    $product_id = (int)$_GET['product_id'];
    $return_url = $_GET['return_url'];
    
    if (isset($_SESSION['cart'][$product_id])) {
        $_SESSION['cart'][$product_id]++;
    } else {
        $_SESSION['cart'][$product_id] = 1;
    }
    
    header("Location: $return_url");
    exit();
} else {
    header("Location: products.php");
    exit();
}
?>