I have two sites, one for the US which is on the root of the domain .com and I have a copy of the site in a directory called /uk aimed towards UK customers.
Here is the code I have set up that works fine when I use a test blank php page, I'm using with a geoplugin class.
<?php ob_start();?>
<?php require_once('geoplugin.class.php');$geoplugin = new geoPlugin(); ?>
<?php $country = $geoplugin->locate();?>
<?php
$countryName= $geoplugin->countryName ;
$ukCountry = 'http://www.mywebsite.com/uk/';
$mainSite = 'http://www.mywebsite.com/';
//UK
if ($countryName =="United Kingdom")
{
header('Location: '.$ukCountry);
}else{
header('Location: '.$mainSite);
?>
I am connecting to the above page via an include statement and works fine as a test.
But what I want to happen is when a visitor will comes to the main site and then check the country of origin and if the country is United Kingdom then forwards to the UK version.
I want to install this on a Wordpress site but when I place the 'include' statement I'm getting the error
Warning: Cannot modify header information - headers already sent by
I've read up a lot about output buffering and I I've tried a number of things to get it to work but I can't get it to forward it correctly.
I know there is a chance of a infinite loop with the above code but I will remove the else statement if to stop this.
Basically I want the the site to check the country is the UK if so forward to the UK site and if not just load the page normally.
Any suggestions welcomed.