<?php ob_start();

$servername = "localhost";
$username = "ndylnqqa_kingmkn";
$password = "kINGmkn@100%";
$dbname = "ndylnqqa_test";

// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);

// Check connection
if (!$conn) {
    die("Connection failed: " . mysqli_connect_error());
}

$current_page = basename($_SERVER['PHP_SELF']);

//echo $current_page;

$sql = mysqli_query($conn, "SELECT * FROM `mail_settings` WHERE 1");
$mailer =mysqli_fetch_assoc($sql);
$myUrl = $mailer['url'];


$referral_sql = mysqli_query($conn, "SELECT * FROM `referral_settings` WHERE 1");
$referral =mysqli_fetch_assoc($referral_sql);
$bot_bonus = $referral['bot_bonus'];
$max_referral_discount = $referral['max_referral_discount'];
$discount_per_referral = $referral['discount_per_referral'];




// Base URL configuration
define('BASE_URL', 'http://localhost/ai trading');

$sitename = 'E-Finance Loans';
$sitelogo = BASE_URL.'/assets/logo.png';
$siteicon = BASE_URL.'/assets/icon.png';

 

if (function_exists('openssl_random_pseudo_bytes')) {
    $new_token = bin2hex(openssl_random_pseudo_bytes(32));
} else {
    $new_token = md5(uniqid(mt_rand(), true)) . sha1(uniqid(mt_rand(), true));
}


// Get Device Type
function getDeviceType() {
    $user_agent = $_SERVER['HTTP_USER_AGENT'];
    
    if (strpos($user_agent, 'Mobile') !== false) {
        return 'Mobile';
    } elseif (strpos($user_agent, 'Tablet') !== false) {
        return 'Tablet';
    } else {
        return 'Desktop';
    }
}

// Get Browser Information
function getBrowser() {
    $user_agent = $_SERVER['HTTP_USER_AGENT'];
    
    if (strpos($user_agent, 'Chrome') !== false) return 'Chrome';
    if (strpos($user_agent, 'Firefox') !== false) return 'Firefox';
    if (strpos($user_agent, 'Safari') !== false) return 'Safari';
    if (strpos($user_agent, 'Edge') !== false) return 'Edge';
    if (strpos($user_agent, 'Opera') !== false) return 'Opera';
    
    return 'Unknown Browser';
}


// Get Location from IP (Basic version - you might want to use an API for more accuracy)
function getLocationFromIP($ip) {
    // For localhost/testing
    if ($ip == '127.0.0.1' || $ip == '::1') {
        return 'Localhost (Development)';
    }
    
    // Simple IP to location (you can use APIs like ipinfo.io for more accuracy)
    $location_data = @json_decode(file_get_contents("http://ipinfo.io/{$ip}/json"), true);
    
    if (isset($location_data['city']) && isset($location_data['country'])) {
        return $location_data['city'] . ', ' . $location_data['country'];
    } elseif (isset($location_data['country'])) {
        return $location_data['country'];
    } else {
        return 'Location not available';
    }
}

$ip_address = $_SERVER['REMOTE_ADDR'];



// Get Operating System
function getOperatingSystem() {
    $user_agent = $_SERVER['HTTP_USER_AGENT'];
    
    if (strpos($user_agent, 'Windows') !== false) return 'Windows';
    if (strpos($user_agent, 'Mac') !== false) return 'Mac OS';
    if (strpos($user_agent, 'Linux') !== false) return 'Linux';
    if (strpos($user_agent, 'Android') !== false) return 'Android';
    if (strpos($user_agent, 'iOS') !== false) return 'iOS';
    
    return 'Unknown OS';
}

$location = getLocationFromIP($ip_address);

// Get current login time
$login_time = date('Y-m-d H:i:s');

// Get IP Address

$login_time = date('Y-m-d H:i:s');
$ip_address = $_SERVER['REMOTE_ADDR'];
$device_type = getDeviceType();
$browser = getBrowser();
$os = getOperatingSystem();
$location = getLocationFromIP($ip_address);
$user_agent = $_SERVER['HTTP_USER_AGENT'];

?>


