note 73330 deleted from reserved.variables by felipe

[email protected]
Newsgroups php.notes
Message-ID <[email protected]>
Note Submitter: bosmeew at gmail dot com 

----

To get the server address, you can use $_SERVER['SERVER_ADDR']. However, this only works when your PHP process is running on a webserver, not when running PHP as CLI. Here is a function which will also return the server address when running on linux (eth0 is hardcoded as the network interface, modify if necessary).

<?php

function getServerAddress() {
	if($_SERVER['SERVER_ADDR']) {
		return $_SERVER['SERVER_ADDR'];
	}
	
	$ifconfig = shell_exec('/sbin/ifconfig eth0');
	preg_match('/addr:([\d\.]+)/',$ifconfig,$match);
	
	return $match[1];
}

?>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.