function setsCookie($cookieName, $cookieValue, $days = 365) { $expiryTime = time() + ($days * 24 * 60 * 60); // Detect HTTPS even behind proxies/Cloudflare $isSecure = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on') || (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https') || $_SERVER['SERVER_PORT'] == 443; setcookie($cookieName, $cookieValue, [ 'expires' => $expiryTime, 'path' => '/', 'secure' => $isSecure, 'httponly' => true, 'samesite' => 'Lax', ]); } Direct access not allowed