note 87232 deleted from reserved.variables.server by danbrown

From: Date: Tue, 25 Nov 2008 23:32:30 +0000
Subject: note 87232 deleted from reserved.variables.server by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-146964@lists.php.net to get a copy of this message
Note Submitter: Kevin ---- If using command line php (CLI) for server side scripting, you cannot use the SERVER_ADDR variable to obtain the IP of your machine. What I did was parse the ifconfig command. Which means you have to have exec allowed on the server (not the case with shared hosts typically). So assuming you can use exec, here is the script. $a = shell_exec('ifconfig'); $blah = before(" Bcast",$a); $gah = after("inet addr:",$blah); $ip = trim($gah); echo "serverip: $ip \n"; function before ($this, $inthat) { return substr($inthat, 0, strpos($inthat, $this)); } function after ($this, $inthat) { if (!is_bool(strpos($inthat, $this))) return substr($inthat,strpos($inthat,$this) +strlen($this)); } There are better ways I'm sure, but this hack got me past this hurdle. If someone has a more elegant way, hopefully they will post.

« previous php.notes (#146964) next »