3

This one has me baffled.

I'd like to show some content based on the Global variable IP Address. But none of these work:

{if {ip_address} != 127.0.0.2}SHOW THIS{/if}

OR

{if {ip_address} != '127.0.0.2'}SHOW THIS{/if}

OR

{if '{ip_address}' != '127.0.0.2'}SHOW THIS{/if}

I would expect at least the last conditional to work. Is this a parsing issue?

1
  • Thank Low and Bhahkar. Low; I should have referred to your Parse List PDF, I've got it tucked away somewhere. I thought it might be something like that. Mar 15 '13 at 23:10
4

The variable {ip_address} is one of the standard global variables that is parsed last, even after advanced conditionals. That means you can't use it in a conditional.

You can use Mo’ Variables (or Low Variables if you’re already using it) to have {logged_in_ip_address} available as an early parsed var, so you can use it in conditionals.

2

As EE parses {ip_address} after advanced conditionals it easy enough to get that data parsed sooner. I haven't got Low Variables installed on this site otherwise I would use it.

Instead you could add it as a variable to config.php:

$config['ipaddress'] = $_SERVER['REMOTE_ADDR'];

Or I've actually added to my bootstrap file but it achieves the same thing.

1
  • Elliot Lewis - This worked perfectly: $config['ipaddress'] = $_SERVER['REMOTE_ADDR']; Added to Config.php file and all is well. Thank you!
    – user2619
    Jan 16 '14 at 14:53
1

This standard global variable should work with logged in member. See here http://ellislab.com/expressionengine/user-guide/templates/globals/single_variables.html#ip-address

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.