how to get user country name from user ip address in php -
how country name user ip address
i have ip addresses of user country name of user base on user ip address how possible in php ?
function get_client_ip() { $ipaddress = ''; if (getenv('http_client_ip')) $ipaddress = getenv('http_client_ip'); else if(getenv('http_x_forwarded_for')) $ipaddress = getenv('http_x_forwarded_for'); else if(getenv('http_x_forwarded')) $ipaddress = getenv('http_x_forwarded'); else if(getenv('http_forwarded_for')) $ipaddress = getenv('http_forwarded_for'); else if(getenv('http_forwarded')) $ipaddress = getenv('http_forwarded'); else if(getenv('remote_addr')) $ipaddress = getenv('remote_addr'); else $ipaddress = 'unknown'; return $ipaddress; }
try this
function ip_details($ipaddress) { $json = file_get_contents("http://ipinfo.io/{$ipaddress}"); $details = json_decode($json); return $details; } $ipaddress = 'your ip address of user'; $details = ip_details("$ipaddress"); //echo $details->city; echo $details->country; //echo $details->org; //echo $details->hostname;
Comments
Post a Comment