The GeoIP extension can be used to find the exact location of an IP address. Apart from this, the geoPlugin class can be downloaded from −
https://www.geoplugin.com/_media/webservices/geoplugin.class.phps
The country code list can be found in the below link −
https://www.geoplugin.com/iso3166
An index.php file can be placed inside the root folder and the below lines of code can be put inside this index file −
<?php
require_once('geoplugin.class.php');
$geoplugin = new geoPlugin();
$geoplugin->locate();
// create a variable for the country code
$var_country_code = $geoplugin->countryCode;
// redirect based on country code:
if ($var_country_code == "AL") {
header('Location: https://sq.wikipedia.org/');
}
else if ($var_country_code == "NL") {
header('Location: https://nl.wikipedia.org/');
} else {
header('Location: https://en.wikipedia.org/');
}
?>Once the geoplugin class has been downloaded, a new instance is created and given the name ‘geoplugin’. The locate function is called on this instance of the geoplugin class. The same class object’s countryCode is assigned to a variable named ‘var_country_code’. Now, the ‘if’ condition is put to check the letters of the region. Based on this IP address, the redirection to the specific domain takes place.