$userId, 'iat' => time(), 'exp' => time() + (7 * 24 * 60 * 60) ]; // Encode payload $header = json_encode(['typ' => 'JWT', 'alg' => 'HS256']); $base64Header = base64_encode($header); $base64Payload = base64_encode(json_encode($payload)); // Signature $signature = hash_hmac('sha256', $base64Header . "." . $base64Payload, $secretKey, true); $base64Signature = base64_encode($signature); // Token return $base64Header . "." . $base64Payload . "." . $base64Signature; } // Redirect from index.php to the base URL $requestUri = $_SERVER['REQUEST_URI']; if (strpos($requestUri, 'index.php') !== false) { $newUrl = str_replace('index.php', '', $requestUri); header('Location: ' . rtrim($newUrl, '/') . '/'); exit; } // Check if user is logged in $isLoggedIn = isset($_SESSION['agen']); // Get the URL path $path = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH); // Include the appropriate view based on session status and path switch ($path) { case '/lupa_password': include 'autentikasi/forget_pass.php'; break; default: if ($isLoggedIn) { include 'page.php'; } else { include 'autentikasi/aut_akses.php'; exit(); // $token = isset($_SESSION['token']) ? $_SESSION['token'] : null; // if ($token) { // $userId = verifyToken($token); // if (!$userId) { // include 'autentikasi/aut_akses.php'; // exit(); // } // $_SESSION['agen'] = $userId; // include "page.php"; // } else { // include 'autentikasi/aut_akses.php'; // exit(); // } } break; } ?>