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 Quote 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. Quote 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. Quote 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']; Quote 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. Quote Link to comment https://forums.phpfreaks.com/topic/212354-user-ip-address/#findComment-1108086 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.