开发者

Working with PHP $_SERVER['SERVER_ADDR'] variable when used in command line script

It seems as if I cannot use the $_SERVER vars in a command line script in PHP as the return seems to be blank? If this is the case then does an开发者_如何学Pythonyone have a suggestion for getting the IP of the server I am running the script on?

Thanks in advance.


SERVER_ADDR is defined by the webserver as CGI environment variable, and depends upon which interface it listens to. A server might have multiple network addresses.

You can fetch it from either ip addr or ifconfig, preferrably looking for the eth0 interface (most common).

preg_match("/inet (addr:)?(?!127)(\d+(\.\d+){3})/", `ip addr`, $m);


use grep command

http://www.linuxquestions.org/questions/linux-general-1/how-to-get-an-ip-address-from-command-line-522676/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜