<?php
session_start();
include '../connection.php';

// ✅ Only run if user is logged in
if (isset($_SESSION['user_id'])) {
    $userId = $_SESSION['user_id']; 

    $stmt = $conn->prepare("UPDATE tbl_user SET remember_token = NULL WHERE user_id = ?");
    $stmt->bind_param("i", $userId);
    $stmt->execute();
    $_SESSION = [];
    // session_destroy();
    unset($userId);
}

setcookie("remember_token", "", time() - 3600, "/", "", false, true);

header("Location: login.php");
exit();
?>
