note 87232 added to reserved.variables.server
| From: | Kevin at osu1 dot php dot net | Date: | Tue, 25 Nov 2008 23:25:43 +0000 |
| Subject: | note 87232 added to reserved.variables.server | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-146962@lists.php.net to get a copy of this message | ||
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.
----
Server IP: 66.207.199.35
Probable Submitter: 64.253.136.161
----
Manual Page -- http://www.php.net/manual/en/reserved.variables.server.php
Edit -- https://master.php.net/note/edit/87232
Del: integrated -- https://master.php.net/note/delete/87232/integrated
Del: useless -- https://master.php.net/note/delete/87232/useless
Del: bad code -- https://master.php.net/note/delete/87232/bad+code
Del: spam -- https://master.php.net/note/delete/87232/spam
Del: non-english -- https://master.php.net/note/delete/87232/non-english
Del: in docs -- https://master.php.net/note/delete/87232/in+docs
Del: other reasons-- https://master.php.net/note/delete/87232
Reject -- https://master.php.net/note/reject/87232
Search -- https://master.php.net/manage/user-notes.php