Q:

PHP program to print the IP address of a hosted web server

belongs to collection: PHP Miscellaneous

0

Here, we will use $_SERVER['SERVER_ADDR'] superglobal to get the IP address of the hosted server.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Program/Source Code:

The source code to print the IP address of the hosted web server is given below. The given program is compiled and executed successfully.

<?php
//PHP program to print the IP address 
//of a hosted web server.

$IpAddress = $_SERVER['SERVER_ADDR'];

printf("IP Address: %s<br>", $IpAddress);
?>

Output:

IP Address: 127.0.0.1

Explanation:

In the above program, we used $_SERVER['SERVER_ADDR'] super global that returns the IP address of the webserver, which is assigned to the variable $IpAddress. After that, we printed the IP address of the webserver on the webpage.

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

PHP Miscellaneous

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
PHP program to print the server name or website na... >>
<< PHP program to print the version of CGI used by th...