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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
OWASP: Forgery and Phishing

Learn the techniques to avoid forgery and phishing attacks and the types of attacks an application or network may face.

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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.