HEX
Server: Apache/2.4.46 (Ubuntu)
System: Linux localhost 5.11.0-49-generic #55-Ubuntu SMP Wed Jan 12 17:36:34 UTC 2022 x86_64
User: root (0)
PHP: 7.4.16
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
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;
?>