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]
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.
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.