c_pattle Posted September 2, 2010 Share Posted September 2, 2010 I'm trying to get the screen to print out the users IP address so I've used the following code. echo($_SERVER['REMOTE_ADDR']); However this only prints out "::1". Does anyone know why it's printing this and not a proper IP Address? Thanks Link to comment https://forums.phpfreaks.com/topic/212354-user-ip-address/ Share on other sites More sharing options...
landysaccount Posted September 2, 2010 Share Posted September 2, 2010 You can try this: function getIp(){ if ( $_SERVER["HTTP_CLIENT_IP"] ) $ip = $_SERVER["HTTP_CLIENT_IP"]; else if( $_SERVER["HTTP_X_FORWARDED_FOR"] ) $ip = $_SERVER["HTTP_X_FORWARDED_FOR"]; else if( $_SERVER["REMOTE_ADDR"] ) $ip = $_SERVER["REMOTE_ADDR"]; else $ip = "UNKNOWN"; return $ip; } Hope it helps. Link to comment https://forums.phpfreaks.com/topic/212354-user-ip-address/#findComment-1106433 Share on other sites More sharing options...
JonnoTheDev Posted September 2, 2010 Share Posted September 2, 2010 This is because you are running IPv6 on your server. ::1 is the same as 127.0.0.1 (loopback address). Disable IPv6 and use IPv4. Link to comment https://forums.phpfreaks.com/topic/212354-user-ip-address/#findComment-1106434 Share on other sites More sharing options...
Dragosvr92 Posted September 6, 2010 Share Posted September 6, 2010 um.. why did you added those ( ) ? This should work fine.. if its not it must be what Neil said echo $_SERVER['REMOTE_ADDR']; Link to comment https://forums.phpfreaks.com/topic/212354-user-ip-address/#findComment-1108041 Share on other sites More sharing options...
Hypnos Posted September 7, 2010 Share Posted September 7, 2010 Are you accessing the page from the server? If so, ::1 is correct. As mentioned it's the same as 127.0.0.1. Although I don't agree that you should disable IPv6. It's working correctly. Link to comment https://forums.phpfreaks.com/topic/212354-user-ip-address/#findComment-1108086 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.