<?php 
@session_start();
if (!isset($_SESSION['id'])){
header('location: ../../login.php');
}
$id_session = $_SESSION['id'];

include('dbcon.php');
$user_query = mysqli_query($conn, "select *  from user where id='$id_session'")or die(mysqli_error());
    $row = mysqli_fetch_array($user_query);

    $full_name = $row['full_name'];
    $email = $row['email'];
    $phone_number = $row['phone_number'];
         $country = $row['country'];
         $avialable_balance = $row['avialable_balance'];
         $earnings = $row['earnings'];
          $password = $row['password'];
        
    $image2 = $row['image2'];
    $date = date('jS F, Y');
     $role = $row['role'];
       
       ?>
       <?php
function getUserIP() {
    // Check for shared internet/ISP IP
    if (!empty($_SERVER['HTTP_CLIENT_IP']) && filter_var($_SERVER['HTTP_CLIENT_IP'], FILTER_VALIDATE_IP)) {
        return $_SERVER['HTTP_CLIENT_IP'];
    }
    // Check for IPs passing through proxies
    if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
        // May contain multiple IPs, use the first valid one
        $ips = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']);
        foreach ($ips as $ip) {
            $ip = trim($ip);
            if (filter_var($ip, FILTER_VALIDATE_IP)) {
                return $ip;
            }
        }
    }
    // Return remote address
    return $_SERVER['REMOTE_ADDR'];
}

$user_ip = getUserIP();

$api_url = "http://ip-api.com/json/{$user_ip}?fields=country,countryCode";
$response = file_get_contents($api_url);
$data = json_decode($response, true);

if ($data && isset($data['country'])) {
    //success
} 

?>