A
A
Artem2018-02-01 13:19:35
PHP
Artem, 2018-02-01 13:19:35

What is wrong with the code (Sypex Geo API)?

Hello, I want to set up a georedirect. Googling found SypexGeo , and this code (which is below). Everything seems to work, more precisely it does not give errors, but it does not determine the country and the redirect occurs via a spare link (
Help the noob) If there is an easier way, please share.
<?php
// Include and instantiate:
include("SxGeo.php");
$SxGeo = new SxGeo('SxGeo.dat');
// Optional step, trying to determine the user's IP more accurately:
function getIP(){
if (!empty($_SERVER['HTTP_CLIENT_IP'])){
//check ip from share internet
$ip = $_SERVER['HTTP_CLIENT_IP'];
}elseif(!empty($_SERVER['HTTP_X_FORWARDED_FOR'
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
} else {
$ip = $_SERVER['REMOTE_ADDR'];
}
return $ip;
}
// Define country and city:
$ip = getIP(); // or $_SERVER['REMOTE_ADDR'];
echo ($SxGeo->getCountry($ip));
echo '';
print_r($SxGeo->getCityFull($ip)); // All information about the city
echo '';
// That is, if you want to change links for Russian residents, then something like this:
if($SxGeo->getCountry($ip) == 'AM') {
header('Location: https://ru.wikipedia.org/ wiki/Armenia ');
exit;
}elseif($SxGeo->getCountry($ip) == 'DE') {
header('Location: https://ru.
exit;
} else {
header('Location: https://ru.wikipedia.org/wiki/ISO_3166-1 ');
exit;
}
//Countries are defined in ISO 3166-1 https://ru.wikipedia.org/wiki/ISO_3166-1
?>

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question