/home/ejrndhmu/.trash/index.php.6
<?php
// Auto redirect from domain utama to user login
require_once 'config/database.php';
require_once 'includes/functions.php';

// Start session to check if user is already logged in
startSecureSession();

// Ensure custom domain column exists
ensureCustomDomainColumn();

// Check for custom domain access
$currentDomain = $_SERVER['HTTP_HOST'] ?? '';
$reseller = getResellerByCustomDomain($currentDomain);

if ($reseller && $reseller['custom_domain_status'] === 'active') {
    // This is a custom domain access, redirect to reseller catalog
    $_SESSION['reseller_domain'] = $currentDomain;
    $_SESSION['reseller_id'] = $reseller['id'];
    header('Location: catalog.php?reseller_id=' . $reseller['id']);
    exit();
}

// Check if user is already logged in
if (isset($_SESSION['logged_in']) && $_SESSION['logged_in'] === true) {
    // Redirect based on user role
    switch ($_SESSION['role']) {
        case 'admin':
            header('Location: admin/');
            break;
        case 'reseller':
            header('Location: reseller/');
            break;
        case 'user':
        default:
            header('Location: user/');
            break;
    }
    exit();
}

// If not logged in, redirect to user login page
header('Location: login.php');
exit();
?>