The simplest way to collect the Client/Visitor IP address using PHP is the REMOTE_ADDR.
Pass the 'REMOTE_ADDR' in PHP $_SERVER variable. It will return the IP address of the visitor who is currently viewing the webpage.
Get the IP address of the website
<?phpecho'User IP Address : '.$_SERVER['REMOTE_ADDR'];?>
/*
I Hope it will help you.
Namaste
Stay Home Stay Safe
*/
#to best handle proxies use this:if(!empty($_SERVER['HTTP_CLIENT_IP'])){$ip=$_SERVER['HTTP_CLIENT_IP'];}elseif(!empty($_SERVER['HTTP_X_FORWARDED_FOR'])){$ip=$_SERVER['HTTP_X_FORWARDED_FOR'];}else{$ip=$_SERVER['REMOTE_ADDR'];}
//You can use an api://Link to documentation: https://ip-get-geolocation.com/documentation/$LocationArray=json_decode(file_get_contents('http://ip-get-geolocation.com/api/json/35.188.125.133'),true);echo$LocationArray['country'];echo$LocationArray['city'];echo$LocationArray['region'];echo$LocationArray['timezone'];
// Function to get the client IP addressfunctionget_client_ip(){$ipaddress='';if(getenv('HTTP_CLIENT_IP'))$ipaddress=getenv('HTTP_CLIENT_IP');elseif(getenv('HTTP_X_FORWARDED_FOR'))$ipaddress=getenv('HTTP_X_FORWARDED_FOR');elseif(getenv('HTTP_X_FORWARDED'))$ipaddress=getenv('HTTP_X_FORWARDED');elseif(getenv('HTTP_FORWARDED_FOR'))$ipaddress=getenv('HTTP_FORWARDED_FOR');elseif(getenv('HTTP_FORWARDED'))$ipaddress=getenv('HTTP_FORWARDED');elseif(getenv('REMOTE_ADDR'))$ipaddress=getenv('REMOTE_ADDR');else$ipaddress='UNKNOWN';return$ipaddress;}
The simplest way to collect the Client/Visitor IP address using PHP is the REMOTE_ADDR.
Pass the 'REMOTE_ADDR' in PHP $_SERVER variable. It will return the IP address of the visitor who is currently viewing the webpage.
Get the IP address of the website
<?phpecho'User IP Address : '.$_SERVER['REMOTE_ADDR'];?>