我有下一个php代码:
<?php
$ip = shell_exec("/sbin/ifconfig | grep 'inet:'| grep -v '127.0.0.1' | cut -d: -f2 | awk '{ print $1}'");
echo $ip;
?>
当我从命令行 ( $php5 ip.php
) 运行它时它工作正常,但是当我从浏览器运行它时它什么也不显示 ( http://localhost/ip.php
)。
顺便说一句,我正在尝试打印我的 IP 地址,但每当我使用时,$_SERVER['SERVER_ADDR'];
我都会得到127.0.0.1
.