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

url redirection based on Location

Discussion in 'Cloaking and Content Generators' started by sapo, Dec 17, 2011.

  1. sapo

    sapo Power Member

    Joined:
    Feb 25, 2008
    Messages:
    510
    Likes Received:
    281
    I need a redirection script that will redirect all USA traffic to one page and every other to another. let me know. I need this ASAP so whoever can help Gets rep whenever I see your post lol
     
  2. sirgold

    sirgold Supreme Member

    Joined:
    Jun 25, 2010
    Messages:
    1,260
    Likes Received:
    645
    Occupation:
    Busy proving the Pareto principle right
    Location:
    A hot one
    Download the appropriate files for php here: maxmind.com

    This should do the trick ;)

    Code:
    <?php
    
    include("geoip.inc");
    $ip=$_SERVER['REMOTE_ADDR'];
    $gi = geoip_open("GeoIP.dat",GEOIP_STANDARD);
    
    $country_code = geoip_country_code_by_addr($gi, "$ip");
    
    geoip_close($gi);
    
    switch($country_code) {
      case "US": header("Location: http://US-URL"); break;
      default: header("Location: http://RestOfTheWorld-URL");
    }
    ?>
    
     
    • Thanks Thanks x 1
  3. sapo

    sapo Power Member

    Joined:
    Feb 25, 2008
    Messages:
    510
    Likes Received:
    281
    Thanks But I couldent figure it out, Just gives me a blank page no redirection happens
     
  4. arcticfang

    arcticfang Regular Member

    Joined:
    Aug 7, 2010
    Messages:
    251
    Likes Received:
    209
    Are the geoip.dat and geoip.inc files both inside the same folder as the page?
     
    • Thanks Thanks x 1
  5. sapo

    sapo Power Member

    Joined:
    Feb 25, 2008
    Messages:
    510
    Likes Received:
    281
    I might sound dumb but I couldent find no geoip.dat

    I have the geoip.inc but no .dat

    LOL I am a idiot I just had to scroll down and read some more, damn their font too small thats my excuse lol
     
  6. sapo

    sapo Power Member

    Joined:
    Feb 25, 2008
    Messages:
    510
    Likes Received:
    281
    now both the files are in the same folder but still no redirection just blank
     
  7. arcticfang

    arcticfang Regular Member

    Joined:
    Aug 7, 2010
    Messages:
    251
    Likes Received:
    209
    Could you paste the entire code you have here? :)
     
  8. sapo

    sapo Power Member

    Joined:
    Feb 25, 2008
    Messages:
    510
    Likes Received:
    281
    its the same as that person provided

    Code:
    <?php
    
    include("geoip.inc");
    $ip=$_SERVER['REMOTE_ADDR'];
    $gi = geoip_open("GeoIP.dat",GEOIP_STANDARD);
    
    $country_code = geoip_country_code_by_addr($gi, "$ip");
    
    geoip_close($gi);
    
    switch($country_code) {
      case "US": header("Location: http://yahoo.com"); break;
      default: header("Location: http://google.com");
    }
    ?>
    and i have geoio.inc and GeoIP.dat in the same directory as this index.html file
     
  9. sirgold

    sirgold Supreme Member

    Joined:
    Jun 25, 2010
    Messages:
    1,260
    Likes Received:
    645
    Occupation:
    Busy proving the Pareto principle right
    Location:
    A hot one
    The code works great, just retested on one of my servers OP.

    1. Delete the 2 files geoip.inc and GeoIP.dat you have now (maybe tainted?)

    2. Make sure you get the geoip.inc from here:

    http://geolite.maxmind.com/download/geoip/api/php/geoip.inc

    3. get geoip.dat.gz (that you'll decompress so you'll end up with GeoIP.dat) from here:

    http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz

    Retry and it'll work for sure.

    HTH! :)

     
    • Thanks Thanks x 1
  10. sapo

    sapo Power Member

    Joined:
    Feb 25, 2008
    Messages:
    510
    Likes Received:
    281
    Did everything you said and still just blank and when i check the source the code is their but it just doesnt trigger a redirection.
     
  11. Autumn

    Autumn Elite Member

    Joined:
    Nov 18, 2010
    Messages:
    2,197
    Likes Received:
    3,041
    Occupation:
    I figure out ways to make money online and then au
    Location:
    Spamville
    Are you using this on an html page? You shouldn't be able to see any source code when you load the page in your browser from your web server. Your page must have a .php file extension and you should be inserting that code before the opening <html> tag. You must test this on a web server - just opening the page in your browser from your local hard drive won't parse the php code.

    If you want to parse .html files for php includes, you can set that up in your .htaccess file (google "parse php in html htaccess").
     
    • Thanks Thanks x 1
  12. sapo

    sapo Power Member

    Joined:
    Feb 25, 2008
    Messages:
    510
    Likes Received:
    281
    LMFAO soon as i read that I faced Palmed, Its works man, Thankfs for clearing that up.. Thanks evefyoen for their help
     
  13. arcticfang

    arcticfang Regular Member

    Joined:
    Aug 7, 2010
    Messages:
    251
    Likes Received:
    209
    Oh wow, that's hilarious. lol Glad everything worked out. :)
     
    • Thanks Thanks x 1
  14. sirgold

    sirgold Supreme Member

    Joined:
    Jun 25, 2010
    Messages:
    1,260
    Likes Received:
    645
    Occupation:
    Busy proving the Pareto principle right
    Location:
    A hot one
    Checklist:

    1. You put the above code into a file with a php extension, right (not htm/html)?
    2. You are testing this with a hosting that actually supports php (you never know...)?
    3. To do some infamous "printf debugging" change this part 'header("Location: http://yahoo.com");' with 'echo "I am a US visitor";' and see if it shows up.

    If this is not the case it eludes me how such a simple snippet wouldn't work for ya.
     
    • Thanks Thanks x 2