1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Geoip to the US but every other country to a different URL

Discussion in 'PHP & Perl' started by Inception_AC, Nov 26, 2013.

  1. Inception_AC

    Inception_AC Jr. Executive VIP Jr. VIP Premium Member

    Joined:
    Feb 16, 2011
    Messages:
    1,620
    Likes Received:
    1,132
    Hey

    i have a geoip setup and it works fine, however im wanting all US traffic to go to one url and the rest of the world goto a different url.

    is there a quick way of doing this without adding every country code into my
    php file?

    thanks!
     
  2. innozemec

    innozemec Jr. VIP Jr. VIP

    Joined:
    Aug 19, 2011
    Messages:
    5,290
    Likes Received:
    1,799
    Location:
    www.Indexification.com
    Home Page:
  3. Inception_AC

    Inception_AC Jr. Executive VIP Jr. VIP Premium Member

    Joined:
    Feb 16, 2011
    Messages:
    1,620
    Likes Received:
    1,132
    <?php
    require_once("geoip/geoip.inc");


    $gi = geoip_open("geoip/GeoIP.dat",GEOIP_STANDARD);


    $country_code = geoip_country_code_by_addr($gi, $_SERVER['REMOTE_ADDR']);
    geoip_close($gi);
    if($country=='US')
    $url='http://URL';
    else
    $url='http://URL';


    ?>


    Doesnt work :S
     
  4. tratata

    tratata Newbie

    Joined:
    Jul 26, 2013
    Messages:
    14
    Likes Received:
    5
    Have you set any redirect?

    Code:
    <?php
    
    header([COLOR=#800000]"Location: " . $url[/COLOR]);
    [COLOR=#00008B]die[/COLOR]();
    
    
     
  5. barigain

    barigain Junior Member

    Joined:
    Aug 23, 2012
    Messages:
    100
    Likes Received:
    12
    <?php
    require_once("geoip/geoip.inc");


    $gi = geoip_open("geoip/GeoIP.dat",GEOIP_STANDARD);


    $country_code = geoip_country_code_by_addr($gi, $_SERVER['REMOTE_ADDR']);
    geoip_close($gi);
    if($country=='US')
    header("Location: $your_us_url");
    else
    header("Location: $your_non_us_url");

    exit;


    ?>