- Download geoip.inc (PHP API) and GeoIP.dat (GeoLite Country Database) from MaxMind.com.
- Create a new folder on our webroot (we will name ours "geoip") and upload geoip.inc and GeoIP.dat into that folder.
- Add this code at the top of your index.php file, or any other page that needs to redirect to another domain:
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_code == 'AU'){
header('Location: http://asdfg.com.au');
}
elseif($country_code == 'GB'){
header('Location: http://asdfg.co.uk');
} - Save and upload the index.php to your webroot.
- To test, you can use an Australian or UK proxy to access your site, and it should redirect accordingly.
I was also able to use this into a Drupal website and it works well - I added the codes into the index.php file. You can also redirect users to subdomains. Let me know if this works for you or not.
B0EnlgH8Nqo.. Very nice :)
ReplyDelete