You are here: Home / Topics / How to Get IP Address of Server in PHP

How to Get IP Address of Server in PHP

Filed under: PHP on 2023-06-30 06:26:52

Use the following code if you want to display the IP address of the server. Simply copy the code to a text file and save it as a .php file on the server.

For Linux with Apache, use the following code:

 

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


For Windows 2008 R2 with IIS 7.5 Server, use:

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


About Author:
V
Vinay Kumar     View Profile
Hi, I am using MCQ Buddy. I love to share content on this website.