views:

89

answers:

2

i have following php code to get vistor ip

 function VisitorIP()
  { 
  if(isset($_SERVER['HTTP_X_FORWARDED_FOR']))
  $TheIp=$_SERVER['HTTP_X_FORWARDED_FOR'];
  else $TheIp=$_SERVER['REMOTE_ADDR'];
  return trim($TheIp);
  }
  $Users_IP_address = VisitorIP();

but every time i execute this script on my localhost i got ::1 as IP

how can i get exact internet IP & system IP address because my script will run on LAN nwteork and i want to record IP of lan pcs & internet IP and save it in mysql database.

i need PHP code which privide local system IP and system internet IP.

Thanks

+3  A: 

Technically, you are getting the right IP. ::1 is your loopback (localhost) IPv6 address.

Jake
+2  A: 

First, throw this stupid function away, because HTTP_X_FORWARDED_FOR is not an IP address but merely an HTTP header, and make it just

$Users_IP_address = $_SERVER['REMOTE_ADDR'];

Next, you have to set up your server to work with ipv4, not ipv6.
Though it is not really a PHP question and should be asked on the serverfault, provided with full system setup: OS, version, your rights etc.

Col. Shrapnel
see i want a PHP code which privide local system IP and internet IP of system.
air
@air you have to reconfigure your server. What is `Listen` parameter value in the apache's htttpd.comf file?
Col. Shrapnel