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? 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']; ?> 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.) 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 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! 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. Link to comment https://forums.phpfreaks.com/topic/166541-php-ip-address/#findComment-878273 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.