I have been using geoplugin, this way to redirect country code:
<?php
// Array country code
require_once('geoplugin.class.php');
$geoplugin = new geoPlugin();
$geoplugin->locate();
// create a variable for the country code
$var_country_code = $geoplugin->countryCode;
// Redirect Traffic from Country Code
$CodeList = ["US", "CA", "AU"];
// redirect based on country code:
if (in_array($var_country_code, $CodeList)) {
header('Location: http://example.com');
}
?>
Came across MaxMind yesterday I saw that it seems better. And I came across this code here:
<?php
require_once __DIR__ . '/' . 'Db/Reader.php';
require_once __DIR__ . '/' . 'Db/Reader/Decoder.php';
require_once __DIR__ . '/' . 'Db/Reader/InvalidDatabaseException.php';
require_once __DIR__ . '/' . 'Db/Reader/Metadata.php';
require_once __DIR__ . '/' . 'Db/Reader/Util.php'; // new 2014/09
use MaxMind\Db\Reader;
$mmdb= 'GeoLite2-Country.mmdb';
$reader = new Reader( __DIR__ . '/' . $mmdb );
$ipData = $reader->get('000.000.000.000');
echo $ipData['country']['names']['en'];
?>
Is there a way to help redirect using MaxMind just like I was doing with Geoplugin?
I have download all required files from MaxMind for this
Aucun commentaire:
Enregistrer un commentaire