0

I have a landing page www.A.com. I want it to redirect to www.A.com/x for tier 1 counties and www.A.com/y for all other countries. All webites were built and work well. I have put a geo.php in th root folder, redirect all traffic to www.A.com/geo.php It works ok to redirect to www.A.com/y but not www.A.com/x although vistors come from tier 1 countries

The code:

<?php
$a = unserialize(file_get_contents('http://www.geoplugin.net/php.gp?ip='.$_SERVER['REMOTE_ADDR']));
$countrycode= $a['geoplugin_countryCode'];
if (in_array($countrycode, array('us','gb','at','de','ca','ch','fr','it','nl','au','nz','sg','ch')))
    header( 'Location: http://www.A.com/x' ) ;
else 
    header( 'Location: http://www.B.com/y' ) ;
?>

Please check if it's right. Did I miss something?

Bizgirl
  • 3
  • 3

1 Answers1

0

please $countrycode convert into lowercase its all working fine.

<?php
function getUserIP()
{
    // Get real visitor IP behind CloudFlare network
    if (isset($_SERVER["HTTP_CF_CONNECTING_IP"])) {
        $_SERVER['REMOTE_ADDR'] = $_SERVER["HTTP_CF_CONNECTING_IP"];
        $_SERVER['HTTP_CLIENT_IP'] = $_SERVER["HTTP_CF_CONNECTING_IP"];
    }
    $client  = @$_SERVER['HTTP_CLIENT_IP'];
    $forward = @$_SERVER['HTTP_X_FORWARDED_FOR'];
    $remote  = $_SERVER['REMOTE_ADDR'];

    if(filter_var($client, FILTER_VALIDATE_IP))
    {
        $ip = $client;
    }
    elseif(filter_var($forward, FILTER_VALIDATE_IP))
    {
        $ip = $forward;
    }
    else
    {
        $ip = $remote;
    }

    return $ip;
}
$user_ip = getUserIP();
$a = unserialize(file_get_contents('http://www.geoplugin.net/php.gp?ip='.$user_ip));
$countrycode= $a['geoplugin_countryCode'];
if (in_array(strtolower($countrycode), array('us','gb','at','de','ca','ch','fr','it','nl','au','nz','sg','ch')))
    header( 'Location: http://www.A.com/x' ) ;
else
   header( 'Location: http://www.B.com/y' ) ;
?>
Amit Dudhat
  • 116
  • 4