2

I am developing a wordpress plugin for geo location.

This is my curiosity question. Why HTTP_CLIENT_IP not showing anything? REMOTE_ADDR shows my ip.

<?php
$ip = $_SERVER['HTTP_CLIENT_IP'];
echo $ip;
?>
kpmrpar
  • 74
  • 1
  • 7

1 Answers1

0

HTTP_CLIENT_IP is ip from share internet but REMOTE_ADDR is current ip

For Example Function on PHP:

function getRealIpAddr()
{
    if (!empty($_SERVER['HTTP_CLIENT_IP']))   //check ip from share internet
    {
      $ip=$_SERVER['HTTP_CLIENT_IP'];
    }
    elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR']))   //to check ip is pass from proxy
    {
      $ip=$_SERVER['HTTP_X_FORWARDED_FOR'];
    }
    else
    {
      $ip=$_SERVER['REMOTE_ADDR'];
    }
    return $ip;
}
john
  • 57
  • 10
  • Why not just `$_SERVER['REMOTE_ADDR']`? In which cases would someone was to use the other two? – tedi Apr 06 '17 at 05:55
  • It is really easy to [fake the IP](http://stackoverflow.com/a/5092951/2205532) if you trust headers over REMOTE_ADDR; which is generally safe. – alxgb Apr 09 '17 at 16:30