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_address} not working correctly

February 24, 2012 5:23am

Subscribe [2]
  • #1 / Feb 24, 2012 5:23am

    Hello there, EE experts

    According to the EE 2.4 user guide, the {ip_address} global variable is supposed to return the IP address of the currently logged in user. See http://ellislab.com/expressionengine/user-guide/templates/globals/single_variables.html#ip-address

    Unfortunately, though, it’s not working for me. {ip_address} always returns 127.0.0.1, and other things like {exp:ip_to_nation:world_flags type="text"} don’t work correctly either. IP to Nation, for example, always says “Japan”, which is not correct.

    Just for kicks, though, I changed the tag to {logged_in_ip_address} at the same place in one of my templates and it actually worked. Changing the variable that way also returns the correct IP address, and gets IP to Nation working.

    So this, for example, doesn’t work:
    {exp:ip_to_nation:world_flags type="text"}{ip_address}{/exp:ip_to_nation:world_flags}

    But this does:
    {exp:ip_to_nation:world_flags type="text"}{logged_in_ip_address}{/exp:ip_to_nation:world_flags}

    That would be okay if all I needed was the world flags function, but I also need to use a different extension that depends on the user’s IP Address ... and that extension is not working as it should be. I assume the reason is that the standard {ip_address} variable is not being pulled in correctly.

    By the way, when I turn on the Output Profiler I can see the correct value in the “ip address” item under “Session Data” and also in the “REMOTE_ADDR” item in the “HTTP Headers” section.

    Any idea what might be going wrong, and how I can fix this?
    Thanks in advance for any advice you may be able to give.

    Cheers
    Andrew

  • #2 / Feb 24, 2012 5:33pm

    Dan Decker

    7338 posts

    Hi Andrew,

    I’m sorry {ip_address} appears to be returning an incorrect value.

    I wasn’t able to replicate your experience. On my test installation, {ip_address} returned my correct, public ip address. I tested logged in and out of the site.

    Is there anything else about your environment that might be a factor here? Are you running on ExpressionEngine 2.4?

    Are you seeing this on a production server, dev server or local install?

    Cheers,

  • #3 / Feb 24, 2012 11:09pm

    Hi Dan

    Thanks for confirming that it’s working okay for you. At least I know it *should* be working.

    I’ll have to do some poking around to see what I can find out. It’s just really curious to me that {ip_address} is having problems, but {logged_in_ip_address} is working consistently well.

    The environment is currently running on a development server hosted on HostGator, not locally.

    Thanks again ... and wish me luck 😉

    Andrew

  • #4 / Feb 25, 2012 12:01am

    Hi Dan

    Doing a little bit of testing makes things even more interesting ...

    I set up a very simple template with NOTHING BUT the following code:

    ip_address: {ip_address}
    
    You are connecting from <strong>{exp:ip_to_nation:world_flags type="text"}{ip_address}{/exp:ip_to_nation:world_flags}</strong>
    logged_in_ip_address: {logged_in_ip_address}
    
    You are connecting from <strong>{exp:ip_to_nation:world_flags type="text"}{logged_in_ip_address}{/exp:ip_to_nation:world_flags}</strong>

    Which returned the following text:

    ip_address: 124.189.xx.x
    You are connecting from

    logged_in_ip_address: 124.189.xx.x
    You are connecting from Australia

    I then wrapped the same code in a channel entries tag, like so:

    {exp:channel:entries channel="CHANNEL" status="STATUS" url_title="{segment_3}" limit="1" require_entry="yes" disable="pagination|trackbacks" }
    ip_address: {ip_address}
    
    You are connecting from <strong>{exp:ip_to_nation:world_flags type="text"}{ip_address}{/exp:ip_to_nation:world_flags}</strong>
    logged_in_ip_address: {logged_in_ip_address}
    
    You are connecting from <strong>{exp:ip_to_nation:world_flags type="text"}{logged_in_ip_address}{/exp:ip_to_nation:world_flags}</strong>
    {/exp:channel:entries}

    And got the following result in the template:

    ip_address: 127.0.0.1
    You are connecting from Japan

    logged_in_ip_address: 124.189.xx.x
    You are connecting from Australia

    So, in my case at least, the {ip_address} variable *is not* working when it is placed inside channel entry tags, but *is* working when it is outside channel entry tags. And {exp:ip_to_nation} is not working in either case, returning either a blank value or the string Japan. But {logged_in_ip_address} is working in all cases ...

    Do you mind taking a moment to confirm whether or not the same thing happens on your test environment? If you get the correct results with the same code, then I can look in more detail at my own environment. If you get the same pattern, then maybe the bug is somewhere else.

    Thanks in advance for any insight you may be able to give.

    Cheers
    Andrew

  • #5 / Feb 26, 2012 12:52pm

    Sean C. Smith

    3818 posts

    Hi Andrew,

    I just tested this and was able to replicate the problem. I’ve filed a bug report for you on this issue. I encourage you to comment on that thread in order to keep informed of the status of the fix.

    Sean

  • #6 / Feb 28, 2012 3:50pm

    Kevin Cupp

    791 posts

    So, in my case at least, the {ip_address} variable *is not* working when it is placed inside channel entry tags, but *is* working when it is outside channel entry tags. And {exp:ip_to_nation} is not working in either case, returning either a blank value or the string Japan. But {logged_in_ip_address} is working in all cases ...

    Hi Andrew,

    Sorry you’re having these problems. I’d like to make sure I understand the problem. When you place {ip_address} inside of a channel entries tag pair, it renders the IP address for the entry’s author as documented here:

    http://ellislab.com/expressionengine/user-guide/templates/globals/single_variables.html#id2

    So we provide variables like {logged_in_ip_address} to get around that. Does using {logged_in_ip_address} not work with the other add-on you’re trying to use? It sounds like EE is working as intended, but the problem may just be with this third-party add-on. Please let me know if I’m misunderstanding the issue.

    Thanks!
    Kevin

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

ExpressionEngine News!

#eecms, #events, #releases