<?php
session_start();

if (isset($_SESSION['auto_login_url']) && !empty($_SESSION['auto_login_url'])) {
    $redirect_url = $_SESSION['auto_login_url'];
    
    unset($_SESSION['auto_login_url']);
    unset($_SESSION['lead_status']);

    header("Location: " . $redirect_url);
} else {
    unset($_SESSION['lead_status']);
    
    $protocol = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https://" : "http://";
    $host = $_SERVER['HTTP_HOST'];
    header("Location: " . $protocol . $host);
}
exit;
?>