<?php
// Force HTTPS
if (empty($_SERVER['HTTPS']) || $_SERVER['HTTPS'] === "off") {
    $redirect = 'https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
    header('HTTP/1.1 301 Moved Permanently');
    header('Location: ' . $redirect);
    exit();
}

// Secure session settings (before session_start)
ini_set('session.cookie_secure', 1); // Only send over HTTPS
ini_set('session.cookie_httponly', 1); // Not accessible via JS
ini_set('session.use_strict_mode', 1);
ini_set('session.use_only_cookies', 1);

session_name('rubicon_admin');
// Start the session
if (session_status() === PHP_SESSION_NONE) {
    session_start();
}

// Set common security headers
header('X-Frame-Options: DENY'); // Prevent iframe clickjacking
header('X-XSS-Protection: 1; mode=block'); // Basic XSS protection
header("Content-Security-Policy: default-src 'self'; script-src 'self' 'unsafe-inline' https://cdnjs.cloudflare.com https://cdn.jsdelivr.net; style-src 'self' 'unsafe-inline' https://cdnjs.cloudflare.com https://cdn.jsdelivr.net;"); // Optional CSP
