rahul_jjj Posted December 22, 2008 Share Posted December 22, 2008 I am trying to get the IP address of the system through the below code, wherein it returns me the value as 127.0.0.1.. How do I get the real IP address. Can anyone advise.. Posted the code below, 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']; } echo $ip; return $ip; } Quote Link to comment Share on other sites More sharing options...
ngreenwood6 Posted December 22, 2008 Share Posted December 22, 2008 thats because you are probably accessing it from the computer it is running on. try another computer Quote Link to comment Share on other sites More sharing options...
DarkerAngel Posted December 22, 2008 Share Posted December 22, 2008 Thats what I was going to say, I have a very simple code running at: http://darkangel.myartsonline.com/ip.php all that is: IP: <?=$_SERVER['REMOTE_ADDR'] ?> Quote Link to comment Share on other sites More sharing options...
rahul_jjj Posted December 23, 2008 Author Share Posted December 23, 2008 Yes you are correct, I am trying to access from my computer. What do u mean by "try in a different computer". Quote Link to comment Share on other sites More sharing options...
Yesideez Posted December 23, 2008 Share Posted December 23, 2008 127.0.0.1 is localhost which is "home" If you want to post the link (or PM it to me) I can check it for you and see what I get. Quote Link to comment Share on other sites More sharing options...
dmccabe Posted December 23, 2008 Share Posted December 23, 2008 Works for me: echo getRealIpAddr(); 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']; } /*echo $ip;*/ return $ip; } ?> Quote Link to comment Share on other sites More sharing options...
Yesideez Posted December 23, 2008 Share Posted December 23, 2008 Your code is working - I just re-read what you typed. When running local on your PC you will always get 127.0.0.1 To get anything different you'll need to put it online. Quote Link to comment Share on other sites More sharing options...
dmccabe Posted December 23, 2008 Share Posted December 23, 2008 Yeah I tried locally and remotely and both worked fine Quote Link to comment Share on other sites More sharing options...
sledge.ha Posted January 9, 2009 Share Posted January 9, 2009 Thats what I was going to say, I have a very simple code running at: http://darkangel.myartsonline.com/ip.php all that is: IP: <?=$_SERVER['REMOTE_ADDR'] ?> How can I get my local(private) and public IP? My ISP provides me public IP. I have a router and two PC. Debian with apache server is running on one of them and on second one I am testing my scripts (I know local IP of my machines of course). I tried a lot of scripts how to get exactly my ip through PHP scripts, but nothing did get it. When I connect to PHP server through LAN, I get local ip (192.168.1.12). When I connect through my public IP (I have made port forwarding to debian machine), I get public ip (e.g. "91.127.181.218"). But I want to get both of them when I am connecting to my server outside my LAN. That information is stored in IP data, is it possible to get it by PHP scripts? Thanks. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.