一聚教程网:一个值得你收藏的教程网站

热门教程

php获取linux命令结果的实例

时间:2022-06-24 14:46:50 编辑:袖梨 来源:一聚教程网

 

 代码如下复制代码

publicfunctionget_server_ip() {

    if(PHP_SAPI ==='cli'){

        $buffer="";

         $handle= popen("ifconfig eth0|grep 'inet addr'|awk -F'[ :]' '{print $13}'",'r');

            while(!feof($handle)) {

             $buffer.=fgets($handle);

            }

            pclose($handle);

         $server_ip= rtrim($buffer);

    }else{

        if(isset($_SERVER)) {

          if($_SERVER['SERVER_ADDR']) {

           $server_ip=$_SERVER['SERVER_ADDR'];

          }else{

           $server_ip=$_SERVER['LOCAL_ADDR'];

          }

         }else{

          $server_ip=getenv('SERVER_ADDR');

         }

    }

     return$server_ip;

    }

 

热门栏目