We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Trying to use IP to Nation to show country specific home page with no luck

Development and Programming

Spark Creative's avatar
Spark Creative
28 posts
14 years ago
Spark Creative's avatar Spark Creative

Hey there EE Community!

Have a client in Canada whose website caters to US, Canada and Australia. I am using a simple query and the IP to Nation module to attempt to show country specific content for the home page, as well as the toll free number that a user sees in the page’s top heading area. For some reason, my client is only seeing US content. I have checked her IP with the IP to Nation database and it is a Canadian IP address. My code is below… any ideas why this wouldn’t be working? As always, any help is greatly appreciated!

Thanks! Danielle


My country-specific content is within a simple Matrix table.

{exp:channel:entries channel="home"}        
<?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"}    
    {if country_code == 'us' OR segment_2 == 'us'}
        {welcome_content search:cell_1="United States"}
            <h2>{cell_2}</h2>
            {cell_3}
        {/welcome_content}
    {if:elseif country_code == 'ca' OR segment_2 == 'ca'}
        {welcome_content search:cell_1="Canada"}
            <h2>{cell_2}</h2>
            {cell_3}
        {/welcome_content}
    {if:elseif country_code == 'au' OR segment_2 == 'au'}
         {welcome_content search:cell_1="Australia"}
            <h2>{cell_2}</h2>
            {cell_3}
        {/welcome_content}
    {if:else}
        {welcome_content search:cell_1="United States"}
            <h2>{cell_2}</h2>
            {cell_3}
        {/welcome_content}
    {/if}
{/exp:query}
{/exp:channel:entries}

[Mod Edit: Moved to the Development and Programming forum]

       
the3mus1can's avatar
the3mus1can
426 posts
14 years ago
the3mus1can's avatar the3mus1can

Try setting PHP to parse on input in the template’s preferences.

       
Spark Creative's avatar
Spark Creative
28 posts
14 years ago
Spark Creative's avatar Spark Creative

Hey there. Thanks for the reply. I already had the template set to parse on input. Any other ideas?

       
Jonathan Schofield's avatar
Jonathan Schofield
175 posts
14 years ago
Jonathan Schofield's avatar Jonathan Schofield

I think I may have the answer, inferred from the sample code provided over at ip2nation.com…

They have a query that looks like this:

$sql = 'SELECT country FROM ip2nation WHERE ip < INET_ATON("'.$_SERVER['REMOTE_ADDR'].'") 
ORDER BY ip DESC LIMIT 0,1';

So, adapting your sql query from:

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

to:

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

…should be what you need.

It’s worked for me.

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.