1

I've set up ip_to_nation like the user guide says to do it:

{exp:ip_to_nation:world_flags image_url="http://example.com/images/world_flags/"}
    {ip_address}
{/exp:ip_to_nation:world_flags}

But this won't output anything. However, if I hard code the IP address in there, it'll work:

{exp:ip_to_nation:world_flags image_url="http://example.com/images/world_flags/"}
    66.85.128.185
{/exp:ip_to_nation:world_flags}

Any ideas why this might be?

  • What happens if you put {ip_address} in your template outside of the module tags? – Derek Hogue Oct 7 '13 at 14:40
  • Then it'll just output my ip address like I'd expect. – peirix Oct 8 '13 at 6:54
0

Have you visited the IP to Nation module in the CP and hit the 'Update IP Database' button on the top right?

Without doing that, there are no IPs to check against and the tag won't work as expected

| improve this answer | |
  • Yeah, I have, because as I said, when I hard-code the IP address into the ip_to_nation it works. – peirix Oct 8 '13 at 13:54
0

I found the answer by accident, and I'll leave the answer here, in case someone else bumps into this problem.

You need to put the tag-pair inside a channel entry

//Doesn't work
{exp:ip_to_nation:world_flags image_url="http://example.com/images/world_flags/"}
    {ip_address}
{/exp:ip_to_nation:world_flags}

//Works!
{exp:channel:entries limit="1"}
{exp:ip_to_nation:world_flags image_url="http://example.com/images/world_flags/"}
    {ip_address}
{/exp:ip_to_nation:world_flags}
{/exp:channel:entries}

EDIT: So {ip_address} inside channel entries gives me the ip address of the author. However, there is a tag called {logged_in_ip_address}, which will output the users ip address even inside the channel entries tag. BUT! When using this, ip_to_nation fails again.

//Doesn't work either!
{exp:channel:entries limit="1"}
{exp:ip_to_nation:world_flags image_url="http://example.com/images/world_flags/"}
    {logged_in_ip_address}
{/exp:ip_to_nation:world_flags}
{/exp:channel:entries}

EDIT 2: Okay. I ended up doing everything in php because of this. So this is my final solution:

$this->EE->ip_data->find($ip);
include(APPPATH.'config/countries.php');
$cc = $this->EE->locales->alpha3_country_code($tmp);

Which will output the country code of the user, which was basically what I wanted anyway.

| improve this answer | |
  • 1
    The channel entries tag is rendering the {ip_address} variable, not the ip_to_nation tag, it's a valid variable for channel entries. Your solution is picking up the IP of the entry author, not the visitor: ellislab.com/expressionengine/user-guide/modules/channel/… – Iain Urquhart Oct 8 '13 at 11:16
  • @IainUrquhart Oh, crap. But do you have any ideas on why ip_to_nation would work inside channel entries and not outside? – peirix Oct 8 '13 at 13:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.