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.

Using IP to Nation Module to define products/service available?

July 29, 2010 6:22pm

Subscribe [3]
  • #1 / Jul 29, 2010 6:22pm

    ChiefAlchemist

    913 posts

    Is there a way to get the IP to Nation Module to put the nation value into a string? Such that it can used to define products, services and/or content to be displayed?

    Maybe there an add-on for this? Anybody?

  • #2 / Jul 31, 2010 2:02pm

    trenchard

    128 posts

    I checked this out and ran into a number of parse issues with built in variables.  Here is what works for me:

    <?php $ip=$_SERVER['REMOTE_ADDR']; ?>
    
    {exp:query sql="SELECT country as country_code FROM exp_ip2nation WHERE ip < INET_ATON('<?php echo $ip; ?>') LIMIT 1"}
        {country_code}
    {/exp:query}

    Install the IP_to_nation module
    Grab the IP address via PHP
    Use a PHP-based query with the IP address parameter (needs to be processed on INPUT)
    Return the country_code.
    You should be able to build whatever conditionals you need based on this.

    Note:  You’ll need to double check on the use of INET_ATON as I’m not sure my example above builds an accurate parameter string.

  • #3 / Sep 01, 2011 11:21pm

    Spark Creative

    28 posts

    Thank you Mark!

    This worked perfectly for me to show country specific content on a home page!

    Cheers,
    Danielle

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

ExpressionEngine News!

#eecms, #events, #releases