PHP Tutorial

PHP Examples

PHP Practice

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

Here, we are going to learn how to print the IP address of a hosted web server in PHP?
Submitted by Nidhi, on November 24, 2020 [Last updated : March 14, 2023]

Getting IP Address of the Server

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

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

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.

More PHP Programs »





Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.