Why the super global array element $_SERVER['SERVER_ADDR'] is not returning proper value?

42 Views Asked by At

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.

0

There are 0 best solutions below