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

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -