delarge
9/8/2016 - 10:27 PM

Get Country code

Get Country code

<?php
$ip = $_SERVER['REMOTE_ADDR'];
$details = json_decode(file_get_contents("http://www.geoplugin.net/json.gp?ip={$ip}"));

$country_code = $details->geoplugin_countryCode;

// Switch instead of IF
switch ($country_code) {
    case "FR": // France
    case "ES": // Spain etc.
    header("Location: https://the-eu-shop.com/");
    die; // Stop doing anything else
    
    break;
    
    case "US":
    header("Location: https://the-us-shop.com/");
    die;
    
    break;
  
    case "UK":
    header("Location: https://uk-shop.com/");
    die;
  
    // If none of the above...
    default:
    header("Location: https://the-fallback-shop.com/");
    die;
}


?>