note 73330 deleted from reserved.variables by felipe
| From: | felipe@php.net | Date: | Sun, 30 Dec 2007 18:27:04 +0000 |
| Subject: | note 73330 deleted from reserved.variables by felipe | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-134362@lists.php.net to get a copy of this message | ||
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];
}
?>