Jump to content

how to get IP address?


jacko310592

Recommended Posts

hey guys,

 

i have this code which is supposed to get me the IP address of my site visitors:

 

<?php if ($_SERVER['HTTP_X_FORWARD_FOR']) {
$ip = $_SERVER['HTTP_X_FORWARD_FOR'];
} else {
$ip = $_SERVER['REMOTE_ADDR'];
}
?>

 

but all i get back when i test it is:

::1

 

how come the IP isnt showing, and what does "::1" mean?

 

thanks guys

Link to comment
https://forums.phpfreaks.com/topic/183796-how-to-get-ip-address/
Share on other sites

that gives me the same reply :/

any ideas?

 

 

could it be possible that it is showing "::1" because im running the php from my PC at the moment?

 

I do believe that is an IPv6 address. :: is a shortcut to skip blocks that aren't assigned, 1 being the first possible address. Is your server set up to use this, or did you change any settings?

 

EDIT: You're running it from your PC, 127.0.0.1 is localhost AKA ::1 I assume.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.