• Register

How to get client IP address using PHP at server side?

0 like 0 dislike
2,768 views
How to get User IP address using PHP script? I want to display visitor IP address using PHP Code.
asked Mar 21, 2016 by anonymous

1 Answer

0 like 0 dislike
 
Best answer

You can use $_SERVER['REMOTE_ADDR'] like this:

<?php
echo $_SERVER['REMOTE_ADDR'];
?>

There is also another example that can detect IP address behind proxy:

<?php
function GetIP(){
  
$ipaddress =  array();
  if (isset(
$_SERVER['HTTP_CLIENT_IP']))
      
$ipaddress[] = $_SERVER['HTTP_CLIENT_IP'];
  if(isset(
$_SERVER['HTTP_X_FORWARDED_FOR']))
      
$ipaddress[] = $_SERVER['HTTP_X_FORWARDED_FOR'];
  if(isset(
$_SERVER['HTTP_X_FORWARDED']))
      
$ipaddress[] = $_SERVER['HTTP_X_FORWARDED'];
  if(isset(
$_SERVER['HTTP_FORWARDED_FOR']))
      
$ipaddress[] = $_SERVER['HTTP_FORWARDED_FOR'];
  if(isset(
$_SERVER['HTTP_FORWARDED']))
      
$ipaddress[] = $_SERVER['HTTP_FORWARDED'];
  if(isset(
$_SERVER['REMOTE_ADDR']))
      
$ipaddress[] = $_SERVER['REMOTE_ADDR'];
      
  
$ips implode(", "array_unique($ipaddress));
  return 
$ips;
}

?>

answered Mar 21, 2016 by anonymous
selected Mar 21, 2016 by learnipaddress
Please check our IP Tools - This Project sponsored by STANDING Tech Company
...