How to identify server IP address in PHP?

PHPServer Side ProgrammingProgramming

The server IP can be identified with the below line of code −

$_SERVER['SERVER_ADDR'];

The port can be identified using the below line of code −

$_SERVER['SERVER_PORT'];

For PHP version 5.3 and higher, the following lines of code can be used −

$host_addr= gethostname();
$ip_addr = gethostbyname($host_addr);

This can be used when a stand-alone script is being run (which is not running via the web server).

raja
Published on 06-Apr-2020 07:31:02
Advertisements