detect ip for switch website or websotre

<?php
$client_ip=$_SERVER[‘REMOTE_ADDR’];

$json=file_get_contents(“http://ipinfo.io/{$client_ip}/json”);
$details = json_decode($json);
var_dump($details->country);

$country=$details->country;
switch ($country)
{ case “CA”:
case “MX”:
case “US”:
$_SERVER[‘MAGE_RUN_CODE’] = “usd”;
$_SERVER[‘MAGE_RUN_TYPE’] = “website”;
break;
default:
$_SERVER[‘MAGE_RUN_CODE’] = “row”;
$_SERVER[‘MAGE_RUN_TYPE’] = “store”;
}
Mage::run($_SERVER[‘MAGE_RUN_CODE’], $_SERVER[‘MAGE_RUN_TYPE’]);

?>

Leave a Comment