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

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?
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 are a bunch of 'Fixits' from Microsoft that change the relationships of IPv4 and IPv6.
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

Open in new window

Loganathan NatarajanLAMP DeveloperCommented:
Take a look at this link: Same Issue
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().
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).
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 "" is the same that "::1".

There is no problem there.
Thanks Ray, mixed the notation in haste.
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.
Dave BaldwinFixer of ProblemsCommented:
You're welcome, glad to help.
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.
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.