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).