echo $_SERVER["REMOTE_ADDR"] not working right

I had to reinstall my XAMPP today. After having done so, I noticed my application was displaying my IP as ::1 instead of 192.168.0.1.

I use echo $_SERVER["REMOTE_ADDR"] to print the IP in my application, so I did a quick test on what it was outputting. True enough it was outputting ::1 instead of my full IP.

What's going on?? Does anyone know why this is happening and how to correct it?
elepilAsked:
Who is Participating?
 
Dave BaldwinFixer of ProblemsCommented:
That is your correct IPv6 localhost address.  It's not wrong.  You can go into your networking and turn off IPv6 and leave IPv4 if you want to.  Here https://support.microsoft.com/en-us/kb/929852 are a bunch of 'Fixits' from Microsoft that change the relationships of IPv4 and IPv6.
0
 
arnoldCommented:
Are you looking for the IP from which the request is being made?
Are you looking for SERVER_ADDR
The other issue is when are you trying to get this information.

run the following
info.php
<%
phpinfo();
%>

Open in new window

0
 
Loganathan NatarajanLAMP DeveloperCommented:
Take a look at this link: Same Issue
0
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

 
Ray PaseurCommented:
I think you've probably got good answers to this question, but there is a "side effects" issue you need to be aware of, and that is how PHP echo works.  Because of PHP type coercion, echo will actually change the data you're seeing if it is used on anything other than a string data type.  Since most programmers do not test data types in PHP, this presents a bit of a risk.  If you try to print data, PHP will need that data to be converted to the string data type.  In object-oriented PHP, this may "helpfully" invoke __toString() behind the scenes.  For your own edification, try using echo to print out the contents of an array.  Just echo $_SERVER and see what you get.  This kind of PHP "magic" can be astonishingly unhelpful, especially if you've encountered an unexpected data element.  You will want to know what type it is, as well as what it contains.

To that end, the correct tool for data visualization is not echo, but var_dump().
0
 
Ray PaseurCommented:
Sidebar note for arnold... The use of a percent sign in the PHP tags (called "ASP tags" in some writings) is installation-dependent and unreliable.  These are removed in PHP 7.  Instead of writing something like this:

<% /* PHP */ %>

Choose the correct tags like this:

<?php /* PHP */ ?>

Most professionals would choose to follow the basic coding standards of PSR-1 and PSR-2 (Google them).
Reference:
http://php.net/manual/en/language.basic-syntax.phptags.php
https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-1-basic-coding-standard.md
0
 
Martin FernandezCommented:
With $_SERVER["REMOTE_ADDR"] you are requesting the remote IP of your own computer. As in this case your computer provided the IPv6 local address to PHP you need to know that "127.0.0.1" is the same that "::1".

There is no problem there.
0
 
arnoldCommented:
Thanks Ray, mixed the notation in haste.
0
 
elepilAuthor Commented:
Best solution goes to Dave Baldwin because he not only provided an explanation for the issue I posted about, but also provided a solution.

Thanks to all who responded.
0
 
Dave BaldwinFixer of ProblemsCommented:
You're welcome, glad to help.
0
 
arnoldCommented:
I would not turn off ipv6 if this is a windows environment. Depending on the system on which it is installed, disabling ipv6 could have adverse effect.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.