<?php 
// Menonaktifkan error reporting untuk produksi
error_reporting(0);

// Menggunakan HTTPS
if (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] !== 'on') {
    header('Location: https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
    exit;
}

// Redirect jika 'index.php' ditemukan di URL
$requestUri = $_SERVER['REQUEST_URI'];
if (strpos($requestUri, 'index.php') !== false) {
    $newUrl = str_replace('index.php', '', $requestUri);
    header('Location: ' . htmlspecialchars($newUrl, ENT_QUOTES, 'UTF-8'));
    exit;
}

session_start();

// Mengamankan koneksi database
include "../config/connect.php"; 
include '../hspages/action_path.php';
include "../config/whatsapp_api.php"; 
include "../list_data/sweetalert.php"; 
include "../config/tanggal_indo.php";

// Tambahkan header keamanan
header("X-Content-Type-Options: nosniff");
header("X-Frame-Options: DENY");
header("X-XSS-Protection: 1; mode=block");

// Regenerasi sesi setelah login
if (isset($_SESSION['agen']) && !isset($_SESSION['session_regenerated'])) {
    session_regenerate_id(true);
    $_SESSION['session_regenerated'] = true;
}

// Validasi sesi
if (!isset($_SESSION['agen'])) {
    if (isset($_GET['lupa_password']) || isset($_GET['otp'])) {
        include "pulihkan_login.php"; 
    } else {
        include "login.php"; 
    }
} else {
    include "page.php"; 
}
?>
