File: /var/www/html/lab-portal/logout.php
<?php
session_start();
// If user is not logged in → directly redirect
if (!isset($_SESSION["user"])) {
header("Location: index.php");
exit;
}
// Prevent browser caching (back button fix)
header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
header("Pragma: no-cache");
header("Expires: 0");
// Get session values
$userId = $_SESSION["user"]["user_id"];
$authToken = $_SESSION["auth_token"];
// ==== CALL LOGOUT API ====
// If your API has a real logout endpoint, replace the URL.
// Using tag/list only because you provided it.
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'http://localhost/messagify/public/api/tag/list',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CUSTOMREQUEST => 'GET',
CURLOPT_HTTPHEADER => array(
'Accept: application/json',
'UserId: ' . $userId,
'AuthToken: ' . $authToken
),
));
$response = curl_exec($curl);
curl_close($curl);
// OPTIONAL: Log API response for debugging
// file_put_contents("logout_log.txt", $response);
// Destroy session completely
session_unset();
session_destroy();
// Prevent back button returning to dashboard
header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
header("Pragma: no-cache");
header("Expires: 0");
// Redirect to homepage
header("Location: index.php");
exit;
?>