0

As per my knowledge the super global array element $_SERVER['SERVER_ADDR'] returns the IP address of the host server.

I've installed PHP using XAMPP server software on my machine that runs on Windows 10 operating system.

I wrote following code in a file titled demo.php(Location of file on my drive is C:\xampp\htdocs\php_playground\demo.php)

The code in a file demo.php is as follows :

<!DOCTYPE html>
<html>
  <body>

  <?php 
    echo $_SERVER['SERVER_ADDR'];
  ?>

  </body>
</html>

and the output of above code I received after running the program in a web browser by hitting the URL http://localhost/php_playground/demo.php is as below :

::1

See the attached screenshot

I'm not understanding this output.

Also, as a part of guessing I run the same program by hitting the URL http://127.0.0.1/php_playground/demo.php in a web browser and I got the following output :

127.0.0.1

I want to know why there is a discrepancy in the output of the same program and why it's not returning proper value in first case?

Thank You.

PHPLover
  • 1
  • 51
  • 158
  • 311
  • 1
    Possible duplicate of [IP Address of the machine in PHP gives ::1 but why?](https://stackoverflow.com/questions/10517371/ip-address-of-the-machine-in-php-gives-1-but-why) and even this: https://stackoverflow.com/questions/3699454/should-a-mamp-return-1-as-ip-on-localhost – Thamilhan Aug 01 '17 at 13:12
  • @Thamilan : My question is different than that question I'm asking for $_SERVER['SERVER_ADDR'] and in that question $_SERVER['REMOTE_ADDR'] is used which is now considered deprecated. – PHPLover Aug 01 '17 at 13:15
  • Wut, `REMOTE_ADDR` is deprecated?! – Anyway, what `SERVER_ADDR` gives you is the IP address of the interface the server received the request on. Since it's using the local loopback interface, that's what you see. What else did you expect? – deceze Aug 01 '17 at 13:26
  • @deceze : Nothing sir and Sorry for my mistake. $_SERVER['REMOTE_ADDR'] is not deprecated. – PHPLover Aug 01 '17 at 13:45

0 Answers0