Forums / Upgrading to 1.5.x / A custom code run well on 139H but does not work on V153 after upgraded

A custom code run well on 139H but does not work on V153 after upgraded

Views: 1,573

Results 1 to 6 of 6
21 Nov 2014, 2:49 AM
#1
mikehw avatar

mikehw

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

21 Nov 2014, 3:03 AM
#2
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: A custom code run well on 139H but does not work on V153 after upgraded

Everywhere you see mysql_ needs to be replaced with the mysqli_ equivalent or use the zen cart code that would provide the desired results without concern of the php version.

All that said, realize that you have just published custom code for which someone either paid for or otherwise may have claimed rights. Hopefully it is not an issue for such a thing...

ZC Installation/Maintenance Support <- Site
Contribution for contributions welcome...

21 Nov 2014, 3:15 AM
#3
mikehw avatar

mikehw

New Zenner

Join Date:
Nov 2010
Posts:
9
Plugin Contributions:
0

Re: A custom code run well on 139H but does not work on V153 after upgraded

Thank you for such quick reply, i will try it to see.

The code was from one of my friend, it`s not business, no issue at all.

21 Nov 2014, 3:22 AM
#4
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: A custom code run well on 139H but does not work on V153 after upgraded

mikehw:

Thank you for such quick reply, i will try it to see.

The code was from one of my friend, it`s not business, no issue at all.

Welcome and by-the-way it's not just a simple change of adding the letter I after mysql. Some functions (and I didn't review each one used) either are completely different or non-existent. Regardless there is additional database access information needed to be included in many if not all of the replacement functions. The specific format can be found in the php manual by searching for php and include the mysql_ function. Once there the mysqli_ equivalent should be linked.

ZC Installation/Maintenance Support <- Site
Contribution for contributions welcome...

21 Nov 2014, 3:50 AM
#5
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: A custom code run well on 139H but does not work on V153 after upgraded

mc12345678:

Everywhere you see mysql_ needs to be replaced with the mysqli_ equivalent or use the zen cart code that would provide the desired results without concern of the php version.
It would be smartest to use the built-in Zen Cart functions for talking to the database, instead of using mysql_ or mysqli_ calls directly.

Plus, you have code for old PHP regex functions that no longer exist, like split(). You can modernize those parts of your code by following the instructions here: http://www.zen-cart.com/entry.php?6-Is-your-plugin-code-safe-for-PHP-5-4-and-5-5-and-5-6

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

22 Nov 2014, 3:26 AM
#6
mikehw avatar

mikehw

New Zenner

Join Date:
Nov 2010
Posts:
9
Plugin Contributions:
0

Re: A custom code run well on 139H but does not work on V153 after upgraded

Thanks a lot, i will take look at it.