Forum Replies Created

Viewing 1 replies (of 1 total)
  • Well first you have to code to detect user location this following code will help you i am using API

    <?php
    function get_client_ip() {
        $ipaddress = '';
        if (isset($_SERVER['HTTP_CLIENT_IP']))
            $ipaddress = $_SERVER['HTTP_CLIENT_IP'];
        else if(isset($_SERVER['HTTP_X_FORWARDED_FOR']))
            $ipaddress = $_SERVER['HTTP_X_FORWARDED_FOR'];
        else if(isset($_SERVER['HTTP_X_FORWARDED']))
            $ipaddress = $_SERVER['HTTP_X_FORWARDED'];
        else if(isset($_SERVER['HTTP_FORWARDED_FOR']))
            $ipaddress = $_SERVER['HTTP_FORWARDED_FOR'];
        else if(isset($_SERVER['HTTP_FORWARDED']))
            $ipaddress = $_SERVER['HTTP_FORWARDED'];
        else if(isset($_SERVER['REMOTE_ADDR']))
            $ipaddress = $_SERVER['REMOTE_ADDR'];
        else
            $ipaddress = 'UNKNOWN';
        return $ipaddress;
    }
    
    $return = array();
    $ip = get_client_ip();
    if (strpos($ip, 'UNKNOWN') !== TRUE)
    {
    $return = json_decode(file_get_contents('https://geoip.nekudo.com/api/'.$ip));
    $code = $return->country->code;
    if (strpos($code, 'US') !== FALSE)
    {   //redirect user to US Page    }
    ?>

    you can use this code in header.php this example is for US visitors for Denmark you have to just replace US country code with Denmark

Viewing 1 replies (of 1 total)