Redirect according to country

I’m stumped. I have a simple php redirect for my site’s order pages. I want visitors from different countries directed to different order pages for my guitar instruction products. I have this and it works:

<?php
$a = unserialize(file_get_contents('http://www.geoplugin.net/php.gp?ip='.$_SERVER['REMOTE_ADDR']));
$countrycode= $a['geoplugin_countryCode'];
if ($countrycode=='AU')
    header( 'Location: http://www.planetalkguitar.com/order_au_.html' ) ;
else 
    header( 'Location: http://www.planetalkguitar.com/order_world_.html' ) ;
?>
<php>

I then tried to add another choice with this:

<?php
$a = unserialize(file_get_contents('http://www.geoplugin.net/php.gp?ip='.$_SERVER['REMOTE_ADDR']));
$countrycode= $a['geoplugin_countryCode'];
if ($countrycode=='AU')
    header( 'Location: http://www.planetalkguitar.com/order_au_.html' ) ;
elseif ($countrycode=='UK')
    header( 'Location: http://www.planetalkguitar.com/order_uk_.html' ) ;
else 
    header( 'Location: http://www.planetalkguitar.com/order_world_.html' ) ;
?>
<php>

… and it doesn’t work. It just goes straight to the last ‘else’, namely the world page. I use proxy servers from both the US and UK to test.

What am I doing wrong?

Kirk

Obvious question is “what is the value of $countrycode when it doesn’t work the way you expect?”. Looking at this it seems like it will be returning “GB” which somehow* stands for “United Kingdom”, not “Great Britain” : http://www.geoplugin.com/iso3166

Not reading the documentation :slight_smile:

(* not being pedantic - “Great Britain” is England, Scotland and Wales, where the “United Kingdom” is England, Scotland, Wales and Northen Ireland. And yes, I had to look it up. I knew it was different, but not exactly why)

1 Like

Thanks, mate, works now.

I’ll stick to playing guitar, I reckon.

Kirk

1 Like

The full name is “The United Kingdom of Great Britain and Northern Ireland”.

Also Britain without the Great is just England and Wales without Scotland. Not sure why Scotland makes it great though.:laughing:

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.