Created
July 26, 2012 03:43
-
-
Save deivisonarthur/3180114 to your computer and use it in GitHub Desktop.
Funcao de Geolocalizacao para Magento
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/*Funcao de Geolocalizacao ###########*/ | |
function get_ip_info($ip,$minuscula) | |
{ | |
if(!$_SESSION['pais']){ | |
$url = "http://www.geoiptool.com/?IP=".$ip; | |
//echo $url; | |
$ch = curl_init(); | |
curl_setopt($ch, CURLOPT_URL,$url); | |
curl_setopt($ch, CURLOPT_FAILONERROR, 1); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); | |
$curl = curl_exec($ch); | |
curl_close($ch); | |
$pattern = "#(align=\"left\" class=\"arial_bold\">(.{2,200})</td>|<img src=\'/flags/.{2,5}\.gif\' alt=\"(.{3,40})\" align=\"absmiddle\" ></td>)#s"; | |
preg_match_all($pattern, $curl, $matches); | |
//print_r($matches); | |
$arrIP_info = array_merge(array_filter($matches[3]),array_filter($matches[2])); | |
$bodytag = strtolower( $arrIP_info[2] ); | |
$bodytag = strip_tags( $bodytag ); | |
$bodytag = str_replace(" Country:", "", $bodytag); | |
$_SESSION['pais'] = $bodytag; | |
if($minuscula == "1"){ | |
return strtolower( $bodytag ); | |
}else{ | |
return $bodytag; | |
}; | |
}elseif($minuscula == "1"){ | |
return $_SESSION['pais']; | |
}else{ | |
return ucfirst($_SESSION['pais']); | |
}; | |
}; | |
$ip = $_SERVER['REMOTE_ADDR']; | |
$pais = get_ip_info( $ip , "1"); | |
if ( $pais == "brazil" ){ | |
echo "<h1>".$pais."!!!!</h1>"; | |
}else{ | |
echo "<h1>".$pais."!!!!</h1>"; | |
//Envia email financeiro | |
}; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment