Reputation: 157
I know may be this questions asked here 1000 times, but i need a specific answer of my question here, I know my code is right but there is something else happening here which i don't know, so don,t duplicate my question please. Thanks :) I am using a code to get the IP address. Here is my code:
<?php
$ipaddress = '';
if (getenv('HTTP_CLIENT_IP'))
$ipaddress = getenv('HTTP_CLIENT_IP');
else if(getenv('HTTP_X_FORWARDED_FOR'))
$ipaddress = getenv('HTTP_X_FORWARDED_FOR'&quot;);
else if(getenv('HTTP_X_FORWARDED'))
$ipaddress = getenv('HTTP_X_FORWARDED');
else if(getenv('HTTP_FORWARDED_FOR'))
$ipaddress = getenv('HTTP_FORWARDED_FOR');
else if(getenv('HTTP_FORWARDED'))
$ipaddress = getenv('HTTP_FORWARDED');
else if(getenv('REMOTE_ADDR'))
$ipaddress = getenv('REMOTE_ADDR');
else
$ipaddress = 'UNKNOWN';
echo $ipaddress; // final ip will be here
?>
and the output is :
::1
I don't know why this giving me this number and not real IP, please help soon. Remember i am working on LOCALHOST
Upvotes: 2
Views: 824
Reputation: 105
This output is the address of the server. It is an IPv6 address (equivalent of 127.0.0.1 in IPv4, which means localhost).
You are getting this because you are probably running this in localhost.
Upvotes: 1