Step 1)Create two static blocks
Step 2 )create main phtml block & call it like home_slider.phtml & save in template/cms/home_slider.phtml
<?php
function get_client_ip_server() {
$ipaddress = '';
if ($_SERVER['HTTP_CLIENT_IP'])
$ipaddress = $_SERVER['HTTP_CLIENT_IP'];
else if($_SERVER['HTTP_X_FORWARDED_FOR'])
$ipaddress = $_SERVER['HTTP_X_FORWARDED_FOR'];
else if($_SERVER['HTTP_X_FORWARDED'])
$ipaddress = $_SERVER['HTTP_X_FORWARDED'];
else if($_SERVER['HTTP_FORWARDED_FOR'])
$ipaddress = $_SERVER['HTTP_FORWARDED_FOR'];
else if($_SERVER['HTTP_FORWARDED'])
$ipaddress = $_SERVER['HTTP_FORWARDED'];
else if($_SERVER['REMOTE_ADDR'])
$ipaddress = $_SERVER['REMOTE_ADDR'];
else
$ipaddress = 'UNKNOWN';
return $ipaddress;
}
$ip_addr=get_client_ip_server();
//echo $ip_addr= '103.36.125.146';
?>
<?php
$url = "http://www.geoplugin.net/json.gp?ip='".$ip_addr."'";
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);
$contents = curl_exec($ch);
if (curl_errno($ch)) {
echo curl_error($ch);
echo "\n<br />";
$contents = '';
} else {
curl_close($ch);
}
if (!is_string($contents) || !strlen($contents)) {
echo "Failed to get contents.";
$contents = '';
}
$contents;
$result=json_decode($contents);
//print_r($result);
?>
<?php
//echo $result->geoplugin_countryCode;
if( $result->geoplugin_countryCode == "IN" ) {
//do something here, like load a specific static block...
echo $this->getLayout()->createBlock('cms/block')->setBlockId('home-carousel-india')->toHtml();
}
else
{
echo $this->getLayout()->createBlock('cms/block')->setBlockId('home-carousel-international')->toHtml();
}
echo $ip = $_SERVER["HTTP_CLIENT_IP"];
?>
Step3) Now this phtml block home_slider.html call it where you want to use, I am using in layout local.xml
<block type="core/template" name="slider" template="cms/home_slider.phtml" before="content"></block>
EmoticonEmoticon