0

I am having an issue on my server (actually local host). I am working on a project which requires ip address of visitor but php $_SERVER['REMOTE_ADDR'] is returning always ::1. I have also tried other functions like this one I found on web.

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;
}

but this also returns the same thing. But I wanna get my external ip as I am the visitor at the time which should be 39.35.*.*. Can anyone please explain, Is there anything wrong with my concepts.

Cœur
  • 37,241
  • 25
  • 195
  • 267
anees
  • 1,777
  • 3
  • 17
  • 26
  • 1
    to get the external ip address(which you want) you must put your site on some live server. – Raman Oct 28 '17 at 10:18
  • 2
    Possible duplicate of https://stackoverflow.com/questions/3003145/how-to-get-the-client-ip-address-in-php – Nigel Ren Oct 28 '17 at 10:18
  • @Raman Are you sure that it does not work without live server because I did not find it anywhere on internet. – anees Oct 28 '17 at 10:21
  • Runing this on the same gateway gave you the `$ip=$_SERVER['REMOTE_ADDR'];` so isn't a bug. –  Oct 28 '17 at 10:21
  • 1
    ::1 is a local machin's IPv6 , if it is IPv4 then it should show 127.0.0.1 . – Raman Oct 28 '17 at 10:23
  • @headmax Thanks for this explaination. I didn't knew that and was about to bash my head to the table. Thanks. – anees Oct 28 '17 at 10:23
  • Ok Then problem is solved. The solution is that I have to put the website on the live server right ? – anees Oct 28 '17 at 10:24
  • Thanks every one, I will try it on live server. – anees Oct 28 '17 at 10:25
  • @AneesIjaz lol your script is running just test it at ouside place for example here http://phpfiddle.org/ –  Oct 28 '17 at 10:27

0 Answers0