Getting Visitors IP Address

+2 Roopavathy Baskaran · August 14, 2014
Hi,

First of all,I thank you a lot for your nice tutorials.Very useful teachings! Nice work !!! Keep it up!!!

I have followed your 65 & 66th Video -  Better Way to Get Visitors IP Address...But I am getting result as 

::1 for 65 th video and 


Notice: Undefined index: HTTP_CLIENT_IP in C:\xampp\htdocs\Ruth-PHP\Visitor_IP\Check_ip_way2.php on line 3

Notice: Undefined index: HTTP_X_FORWARDED_FOR in C:\xampp\htdocs\Ruth-PHP\Visitor_IP\Check_ip_way2.php on line 4
::1

What's wrong with my program?Please help me.

Thanks in advance!!!!

Post a Reply

Replies

Oldest  Newest  Rating
+1 Franz Schmidt · August 14, 2014
Could you please post your code to? :ermm:
+1 Shamal Sandeep · August 31, 2014
Hey I noticed that some of the PHP tutorials are outdated and at the same time ip ::1 is the Ipv6 equivalent for 127.0.0.1 in Ipv4. It's not an error so try to use it or convert it into 127.0.0.1 using a php function.
+1 Jasmin Bakalović · August 16, 2014
I tested your code and instead of $_SERVER, I used getenv().

$http_client_ip = getenv('HTTP_CLIENT_IP');
$http_x_forwarded_for = getenv('HTTP_X_FORWADED_FOR');
$remote_addr = getenv('REMOTE_ADDR');


Probably you are asking yourself now, what is getenv()? With getenv() function you can access to any environment variable. More info: http://php.net/manual/en/function.getenv.php

And, if you worry about this ::1, it's your IPv6 adress => 127.0.0.1. You can solve that problem by configuring apache setings: http://www.fix6.net/archives/2011/02/04/how-to-enable-ipv6-on-apache2/
+1 Roopavathy Baskaran · August 16, 2014
Thank you Jasmin....:)
0 Muhammad Zeeshan · August 28, 2015
It can be corrected  by replacing "localhost" in  url with "127.0.0.1" and then it shows the ip:"127.0.0.1" :)
0 Roopavathy Baskaran · September 1, 2014
Thank you..
0 Nikola Novakovic · September 1, 2014
IPV6 is honestly a little bit far into the future I think. I am not saying it is not awesome but it is still used really on a few occasions. It is not totally relevant to this but just sayin' :) 
0 Roopavathy Baskaran · August 16, 2014
Sorry for late reply............

Here is my code:

<?php

$http_client_ip=$_SERVER['HTTP_CLIENT_IP'];
$http_x_forwarded_for=$_SERVER['HTTP_X_FORWARDED_FOR'];
$remote_addr=$_SERVER['REMOTE_ADDR'];

if(!empty($http_client_ip))
{
$ip_address=$http_client_ip;
}
elseif(!empty($http_x_forwarded_for))
{
$ip_address=$http_x_forwarded_for;
}
else
{
$ip_address=$remote_addr;
}

echo $ip_address;


?>
0 Roopavathy Baskaran · August 16, 2014
Can anyone help me?
  • 1

PHP

107,238 followers
About

Server-side, HTML embedded scripting language used to create dynamic Web pages.

Links
Moderators