<?php
session_regenerate_id(true);

// Set cookie dengan atribut keamanan
setcookie('session_id', session_id(), [
    'expires' => time() + 3600, // 1 jam
    'path' => '/',
    'domain' => '', // Biarkan kosong jika cookie hanya digunakan di domain ini
    'secure' => true, // Hanya kirim melalui HTTPS
    'httponly' => true, // Tidak dapat diakses oleh JavaScript
    'samesite' => 'Strict' // Cegah pengiriman lintas situs
]);

$user_agent = $_SERVER['HTTP_USER_AGENT'] ?? '';
if (preg_match('/python|curl|wget/i', $user_agent)) {
    die('Access Denied');
}

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

?>