I'm trying to get the IP and location data of my visitors but I'm getting an error.
My Code works on localhost but refer no data but not on my online server there is the code:
<?php
//GET th passed data
$page = $_GET['page'];
//GET VISITOR IP
function get_ip(){
if(isset($_SERVER['HTTP_CLIENT_IP'])){
return $_SERVER['HTTP_CLIENT_IP'];
}elseif(isset($_SERVER['HTTP_X_FORWARDED_FOR'])){
return $_SERVER['HTTP_X_FORWARDED_FOR'];
}
else{
return (isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '');
}
}
$ip =get_ip();
if($ip){
$query = unserialize(file_get_contents('http://www.geoplugin.net/php.gp?ip='.$ip));
if($query){
//getting th variabales
$country = $query['geoplugin_countryName'];
$countrycode = $query['geoplugin_countryCode'];
$city = $query['geoplugin_city'];
$regionname = $query['geoplugin_regionName'];
$lat = $query['geoplugin_latitude'];
$long = $query['geoplugin_longitude'];
$timezone = $query['geoplugin_timezone'];
//move the variabales
echo "<script> window.location.assign('../".$page.".php?IP=".$ip."&country=".$country."&countrycode=".$countrycode."&city=".$city."&latitude=".$lat."&longtitude=".$long."&timez=".$timezone."®ionName=".$regionname."&gettingdata= success');</script>";
}else{
echo "<script type='text/javascript'>alert('حدث خطأ ما والرجاء المحاولة في ما بعد')</script>";
echo "<script> window.location.assign('../index.php?getting data = failed');</script>";
}
}else{
echo "<script type='text/javascript'>alert('حدث خطأ يرجى المحاولة في ما بعد')</script>";
echo "<script> window.location.assign('../index.php?getting IP= failed');</script>";
}
?>