AshleyByrom Posted July 19, 2009 Share Posted July 19, 2009 Well, on my previous post I mentioned I am making a basic user login script. I am trying to log IP's a user logs in from but I am stuck at the first hurdle. After a goole search I have tried using <?php //Gets the IP address $ip = getenv("REMOTE_ADDR") ; Echo "Your IP is " . $ip; ?> but when I use that I am given: Your IP is ::1 any help? Quote Link to comment https://forums.phpfreaks.com/topic/166541-php-ip-address/ Share on other sites More sharing options...
darkfreaks Posted July 19, 2009 Share Posted July 19, 2009 Try: <?php $ip = $_SERVER['REMOTE_ADDR']; ?> Quote Link to comment https://forums.phpfreaks.com/topic/166541-php-ip-address/#findComment-878253 Share on other sites More sharing options...
corbin Posted July 19, 2009 Share Posted July 19, 2009 I suggest using $_SERVER['REMOTE_ADDR'].... And, that's the loopback adapter in IPv6, if I remember correctly. (It's equal to 127.0.0.1 in simple terms.) Quote Link to comment https://forums.phpfreaks.com/topic/166541-php-ip-address/#findComment-878254 Share on other sites More sharing options...
AshleyByrom Posted July 19, 2009 Author Share Posted July 19, 2009 Thanks for the fast replies, I tried that but, i face the same problem. My IP Address still seems to be ::1 Quote Link to comment https://forums.phpfreaks.com/topic/166541-php-ip-address/#findComment-878256 Share on other sites More sharing options...
AshleyByrom Posted July 19, 2009 Author Share Posted July 19, 2009 Oh.. now it works? That is highly confusing. I am running apache with PHP on my mac and I also have an external server I am accessing via FTP. Maybe on Apache it doesn't work but on the external server it does. Freaky but, i dont have to worry now. Thanks anyway! Quote Link to comment https://forums.phpfreaks.com/topic/166541-php-ip-address/#findComment-878257 Share on other sites More sharing options...
ignace Posted July 19, 2009 Share Posted July 19, 2009 Read up on this thread: http://www.phpfreaks.com/forums/index.php/topic,260768.msg1229279.html function getip() { if (!empty($_SERVER['HTTP_CLIENT_IP'])) { return $_SERVER['HTTP_CLIENT_IP']; // shared internet } else if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { return $_SERVER['HTTP_X_FORWARDED_FOR']; // behind a proxy } else { return $_SERVER['REMOTE_ADDR']; // directly connected to the internet } } This gives you the the ip address when the user uses shared internet, a proxy or is just directly connected to the internet. Quote Link to comment https://forums.phpfreaks.com/topic/166541-php-ip-address/#findComment-878273 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.