Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
137 views
in Technique[技术] by (71.8m points)

IP Address of the machine in PHP gives ::1 but why?

I am trying to fetch the ip address of my machine through php. For that I am writing the code like:

<?php echo  "<br />".$_SERVER['REMOTE_ADDR'];?>

But this piece of code is not working. It is returning "::1". Please help me how to get the actual IP Address.

question from:https://stackoverflow.com/questions/10517371/ip-address-of-the-machine-in-php-gives-1-but-why

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

::1 is the actual IP. It is an ipv6 loopback address (i.e. localhost). If you were using ipv4 it would be 127.0.0.1.

If you want to get a different IP address, then you'll need to connect to the server through a different network interface.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...