PHP系统命令函数使用分析

yipeiwu_com5年前PHP代码库
复制代码 代码如下:

function execute($cmd) {
     $res = '';
     if ($cmd) {
         if(function_exists('system')) {
             @ob_start();
             @system($cmd);
             $res = @ob_get_contents();
             @ob_end_clean();
         } elseif(function_exists('passthru')) {
             @ob_start();
             @passthru($cmd);
             $res = @ob_get_contents();
             @ob_end_clean();
         } elseif(function_exists('shell_exec')) {
             $res = @shell_exec($cmd);
         } elseif(function_exists('exec')) {
             @exec($cmd,$res);
             $res = join(“\n",$res);
         } elseif(@is_resource($f = @popen($cmd,"r"))) {
             $res = '';
             while(!@feof($f)) {
                 $res .= @fread($f,1024);
             }
             @pclose($f);
         }
     }
     return $res;
 }

相关文章

PHP6 中可能会出现的新特性预览

  这些特性包括:     集成OpCache(OPcache通过对PHP的opcode进行缓存和优化,可以提高PHP程序的执行速度) ...

基于php常用函数总结(数组,字符串,时间,文件操作)

数组:【重点1】implode(分隔,arr) 把数组值数据按指定字符连接起来例如:$arr=array('1','2','3','4');$str=implode('-',$arr);...

PHP简单判断iPhone、iPad、Android及PC设备的方法

本文实例讲述了PHP简单判断iPhone、iPad、Android及PC设备的方法。分享给大家供大家参考,具体如下: 因为工作需要我们需要知道是什么样了用户访问了我网站了,现在的移动设备...

解决dede生成静态页和动态页转换的一些问题,及火车采集入库生成动态的办法

-------------------------------------------------------- 风十三 落伍首发  转载请注明作者和出处 -----...

PHP使用pear自带的mail类库发邮件的方法

本文实例讲述了PHP使用pear自带的mail类库发邮件的方法。分享给大家供大家参考。具体如下: 这里用pear自带的mail类库发邮件,可以用pear install 命令来安装对应的...