ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

IP to Nation problem after updating to EE2.5.2

July 13, 2012 5:14am

Subscribe [4]
  • #1 / Jul 13, 2012 5:14am

    Antenna

    87 posts

    Hi,

    I’m using the IP to Nation Module to ascertain a visitor’s county (so I can hide or show specific content depending on their location) and have achieved this with the following code:

    {exp:query sql="SELECT country FROM exp_ip2nation WHERE ip < INET_ATON('<?php echo $ip; ?>') ORDER BY ip DESC LIMIT 0,1"}{country}{/exp:query}

    ...I don’t pretend to understand the code, but it’s been working nicely 😊

    I’ve just updated the site from EE2.3.1 to EE2.5.2 and the above seems to have broken. Upon visiting the site I get this error:

    Error Number: 1054

    Unknown column ‘ip’ in ‘where clause’

    SELECT country FROM exp_ip2nation WHERE ip < INET_ATON(‘62.133.4.234’) ORDER BY ip DESC LIMIT 0,1

    Filename: modules/query/mod.query.php

    Line Number: 181

    Just wondered if anyone had any ideas what the problem might be.

    IP to Nation version is 3.0.

    I must also say that I’ve attempted the update to 2.5.2 on a copy of the actual site, so I may have done something daft when copying the site across (although the copy appeared to be working fine before the update).

    Any guidance would be greatly appreciated. Thanks!

     

  • #2 / Jul 13, 2012 5:40am

    Andrew Weaver

    206 posts

    I don’t have the fix to hand, but the IP to Nation module’s database structure changed in version 3.0 and the ‘ip’ column does not exist anymore.

    I *think* it was replaced with 2 columns (something like ip_range_low and ip_range_high) so the SQL will need a bit of modifying.

    Andrew

  • #3 / Jul 13, 2012 5:54am

    Andrew Weaver

    206 posts

    Can you just use the exp:ip_to_nation:world_flags tag with the type=text parameter?

    {exp:ip_to_nation:world_flags type="text"}{ip_address}{/exp:ip_to_nation:world_flags}

    Andrew

  • #4 / Jul 13, 2012 6:22am

    Jonathan McGaha

    11 posts

    I saw this somewhere else on the forums a few weeks ago, for your sql try:

    SELECT country FROM exp_ip2nation WHERE unhex('" . $ip. "') BETWEEN ip_range_low and ip_range_high
  • #5 / Jul 13, 2012 6:40am

    Antenna

    87 posts

    Hi Andrew - many thanks for your help.

    I’ve just tried adding the {exp:ip_to_nation:world_flags type="text"} tag to templates on the EE2.5.2 version of the site and also on the version still running on EE2.3.1 (which has IP to Nation version 2.3).

    The 2.3.1 version outputted “United Kingdom”, but the 2.5.2 version didn’t output anything (completely blank) ...not sure why this should happen. I’m guessing I’ve broken something somewhere along the line :ahhh:.

    My understanding is that the {exp:ip_to_nation:world_flags type="text"} tag needs to sit inside {exp:comment:entries} or {exp:channel:entries} tags. Whereas the method I had working before allowed me to set the country as a class, like this:

    <body id="home" class="{exp:query sql="SELECT country FROM exp_ip2nation WHERE ip < INET_ATON('<?php echo $ip; ?>') ORDER BY ip DESC LIMIT 0,1"}{country}{/exp:query}">

    which would output:

    <body id="home" class="uk">

    ...allowing me to hide or show specific content using css.

    This may well not be the best way to achieve what I need, but it’s been working ok so far (any better suggestions would be most welcome!).

    If I can amend my existing method to work with IP to Nation 3.0 that would great. Not being particularly clued-up about SQL I have no idea how to go about modifying this for version 3.0 :red: - can anyone out there point me in the right direction?

    Otherwise, if there’s a method I can use with {exp:ip_to_nation:world_flags type="text"} (outputting the country name as a class) that would also be cool.

    Thanks!

  • #6 / Jul 13, 2012 6:54am

    Andrew Weaver

    206 posts

    This post seems to suggest you might have to process the IP address a bit more in the new version (I think it is now IPv6 compatible).

    http://ellislab.com/forums/viewthread/219139/

    This seems to suggest an SQL query that might work.

    (Sorry - I don’t have an EE 2.5.2 installation to hand to test on until I am back in the office).

    Andrew

  • #7 / Jul 13, 2012 7:00am

    Antenna

    87 posts

    Thanks again, Andrew. I’ll have a read of that link and a try a couple of things out. Cheers!

  • #8 / Jul 16, 2012 11:50am

    Shane Eckert

    7174 posts

    Hey Antenna,

    How are things going? Did you make any progress with the module?

    Please let me know if there is anything I can do to help.

    Cheers,

  • #9 / Jul 17, 2012 9:11am

    Antenna

    87 posts

    Hi Shane,

    Still struggling! Andrew was very helpful and I now grasp what the problem is but I’m not confident about the exact changes I need to make to my code to get it working with IP to Nation 3.0.

    Reluctantly thinking I may have to keep the original version of the site running on EE2.3.1 until I can work the above.

    What I really need is a plugin like the Country Plugin which I used to use on the EE1 version of the site in question, but nothing appears to exist for EE2 unfortunately.

    Thanks,

    Andy

  • #10 / Jul 17, 2012 5:28pm

    Shane Eckert

    7174 posts

    Hey Andy,

    Understood.

    Is there anything else I can do?

    Cheers,

  • #11 / Jul 18, 2012 4:09am

    Antenna

    87 posts

    Hi Shane

    For the time being I guess I just need to keep working at it - thanks for your assistance.

    All the best,

    Andy

  • #12 / Jul 18, 2012 6:24am

    Andrew Weaver

    206 posts

    Hi Andy,

    I knocked together a quick plugin. Would you like to give this a try?

    https://bitbucket.org/ajweaver/ajw_country

    Its pretty untested but let me know if it does what you need to not - it should be fairly easy to add any additional functionality that you need.

    Andrew

  • #13 / Jul 18, 2012 8:37am

    Antenna

    87 posts

    Hi Andrew,

    Wow, that’s really good of you - looks perfect!

    Currently I’ve rolled the site back to EE2.3.1 as I was having a couple of other issues, but will be reattempting the update to 2.5.2 later this week and will give your plugin a try.

    Thanks for all your help with my problem - it’s very much appreciated!

    All the best,

    Andy

  • #14 / Jul 18, 2012 4:20pm

    Shane Eckert

    7174 posts

    Hey Antenna,

    Please do let us know how that goes!

    Thanks for being awesome Andrew!

    Cheers,

  • #15 / Oct 08, 2012 12:13am

    Kaori

    57 posts

    Hello everyone

    Andrew, I needed something like this as well so I installed your plugin, but I got the following error in EE 5.3 when I tried to use the tag.

    Fatal error: Class ‘CI_Model’ not found in /home/user/public_html/system/expressionengine/modules/ip_to_nation/models/ip_to_nation_data.php on line 3

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases