New Zenner
- Join Date:
- Nov 2010
- Posts:
- 9
- Plugin Contributions:
- 0
A custom code run well on 139H but does not work on V153 after upgraded
I have a custom code working on my previous site(v139H), but since upgrade to V153, it seems does not work.
The code located at index.php to automatically redirect IPs that from Canada to my .ca site.
Code here:
function ip2Ipv ($IPaddr) {//$ipaddress = getenv(REMOTE_ADDR);
if ($IPaddr == "") {
return 0;
} else {
$ips = split (".", "$IPaddr");
return ($ips[3] + $ips[2] * 256 + $ips[1] * 65536 + $ips[0] * 16777216);
}
}
function getGeoCountryFromDB($ip) {
// $url="http://api.geoio.com/q.php?key=ZJSxXUl6UGPtSuiw&qt=geoip&d=comma&q=".$ip;
// $handle = @fopen($url, "r");
// if ($handle and 0) {
// $buffer = fgets($handle, 4096);
// $bbb=split(",",$buffer);
// fclose($handle);
// return $bbb[6];
// } else {
$ipv=ip2Ipv($ip);
$sql="select countrySHORT as countrycode from ipcountry where ipFROM<=$ipv and ipTO>=$ipv";
$re=mysql_query($sql);
if (!mysql_errno()){
if (mysql_num_rows($re)>0) {
$country_code=mysql_result($re,0,"countrycode");
if (strlen($country_code)<2) {
$country_code="";
}
} else {
$country_code="";
}
} else {
$country_code="";
}
// }
return $country_code;
}
$ipaddress = getenv(REMOTE_ADDR);
$country_code=getGeoCountryFromDB($ipaddress);
// echo $ipaddress.$country_code;exit;
// var_dump($_GET);exit;
if ($country_code=="CA" and (empty($_GET) or ($_GET['main_page']=="index" and !isset($_GET['cPath'])) and $_GET['from']!='flag')) {
header("Location:http://megadiscstore.ca");
exit;
}
Database upgraded and work no problem, website work no error, just never redirect all Canadian IPs.
Any one can help me that would be very much appreciated.
Mike