views:

288

answers:

4

Hi

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.

Kind regards

Peter

+1  A: 

The variable you're looking for is:

<?php $_SERVER['REMOTE_ADDR']
andre
REMOTE_ADDR also returns ::1
Peter
+2  A: 

use $_SERVER['REMOTE_ADDR']

It will give the IP address

Refer this link for more info about $_SERVER

pavun_cool
that also returns ::1
Peter
Could it possibly be an IPv6 address?
Peter
A: 

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
+1  A: 

::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