4

Possible Duplicate:
should $ip=$_SERVER['REMOTE_ADDR']; return ::1 on a mamp localhost?

I am trying to get the IP address of the website visitor in PHP. I'm expecting $_SERVER['REMOTE_HOST'] to return something like 127.0.0.1, but it's returning ::1.

Community
  • 1
  • 1
Peter
  • 545
  • 4
  • 9
  • 15

4 Answers4

8

::1 is the IPv6 equivalent of 127.0.0.1 - see http://www.juniper.net/techpubs/software/erx/erx50x/swconfig-routing-vol1/html/ipv6-config5.html The long form of that is
0:0:0:0:0:0:0:1 - but the :: stands in for the run of 0's.

Alister Bulman
  • 34,482
  • 9
  • 71
  • 110
2

The variable you're looking for is:

<?php echo $_SERVER['REMOTE_ADDR']; ?>
Andre
  • 3,150
  • 23
  • 23
2

use $_SERVER['REMOTE_ADDR']

It will give the IP address

Refer this link for more info about $_SERVER

Pavunkumar
  • 5,147
  • 14
  • 43
  • 69
0

There are two possibilities here:

  1. the address is ipv6. this has already been pointed out so i think this isn't the case
  2. there is a firewall running on the server. as you say this is your local web server, check for any firewalls on it as some firewalls do block the server information.

Let know how it goes.

pinaki
  • 5,393
  • 2
  • 24
  • 32