Results 1 to 6 of 6
  1. #1
    Join Date
    Nov 2010
    Posts
    9
    Plugin Contributions
    0

    Default 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

  2. #2
    Join Date
    Jul 2012
    Posts
    16,718
    Plugin Contributions
    17

    Default 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...

  3. #3
    Join Date
    Nov 2010
    Posts
    9
    Plugin Contributions
    0

    Default 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.

  4. #4
    Join Date
    Jul 2012
    Posts
    16,718
    Plugin Contributions
    17

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

    Quote Originally Posted by mikehw View Post
    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...

  5. #5
    Join Date
    Jan 2004
    Posts
    66,364
    Blog Entries
    7
    Plugin Contributions
    274

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

    Quote Originally Posted by mc12345678 View Post
    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-...nd-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.

  6. #6
    Join Date
    Nov 2010
    Posts
    9
    Plugin Contributions
    0

    Default 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.

 

 

Similar Threads

  1. v151 my custom jQuery code does not work, why??
    By tlyczko in forum Templates, Stylesheets, Page Layout
    Replies: 12
    Last Post: 27 Dec 2012, 12:09 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg
Zen-Cart, Internet Selling Services, Klamath Falls, OR