<?php
require_once "../../config/constants.php";
require_once "../../database/db_connect.php";

updateSessionId($_SESSION['id']);
// Unset all of the session variables
$_SESSION = array();

// Destroy the session.
session_destroy();

// Redirect to login page
header("location:../../index.php");
exit;

function updateSessionId($userID)
{
    $sql = "UPDATE users SET session_id = NULL WHERE id = :id";
    $stmt = PDO_CONNECTION->prepare($sql);
    $stmt->bindParam(":id", $userID);
    $stmt->execute();
}
