65.gif

Search (advanced search)
Use this Search form before posting, asking or make a new thread.
Tips: Use Quotation mark to search words (eg. "How To Make Money Online")

12-23-2011, 09:51 AM
Post: #1
How To Redirect Visitors to Different Urls According to their Location
If you want your US visitors to visit url1 and rest of the world visitors to see url2 then use this code below :

First you need to use this php script on the page which you want to behave like you want, before opening html tag if the page already exists or just create a .php page with the code below :

PHP 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");
}
?>

Now you also need to download these two files and put them in the same folder as the above file :

1. http://geolite.maxmind.com/download/geoi.../geoip.inc - you will get geoip.inc file from here

2. http://geolite.maxmind.com/download/geoi...oIP.dat.gz - Extract this and you will get GeoIP.dat

That's it, enjoy! Wink

I'll share more helpful information/guide soon. [Image: smile.gif]
Press THANKS or REP me if you found it useful. [Image: cool.gif]
12-23-2011, 02:34 PM
Post: #2
RE: How To Redirect Visitors to Different Urls According to their Location
Thank you .
12-23-2011, 03:12 PM
Post: #3
RE: How To Redirect Visitors to Different Urls According to their Location
Thanks i will try this on my site ...
11-18-2013, 10:13 AM
Post: #4
RE:
Thanks, works nice!

Here's the working link for geoip.inc

I have a manual language selector, how would I adapt this script so the manual overrides the automatic one?

Example:

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 "BR": header("Location: https://mysite.com/br"); break;
                          case "ES": header("Location: https://mysite.com/es"); break;
              default: header("Location: https://mysite.com");
            }
?>
Select your language:

<a href="mysite.com">English</a>
<a href="mysite.com/es">Spanish</a>
<a href="mysite.com/br">Portuguese</a>




71.gif