PHP系统命令函数使用分析

yipeiwu_com6年前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;
 }

相关文章

php判断正常访问和外部访问的示例

php判断正常访问和外部访问 复制代码 代码如下: <?php session_start(); if(isset($_POST['check'])&&!empty($_POST[...

PHPEXCEL 使用小记

首先是使用PHP Reader 读取Excle内容: 复制代码 代码如下: require("//www.jb51.net/PHPExcel/Classes/PHPExcel.php")...

php类常量的使用详解

可以把在类中始终保持不变的值定义为常量。在定义和使用常量的时候不需要使用 $ 符号。 常量的值必须是一个定值,不能是变量,类属性,数学运算的结果或函数调用。 接口(interface)中...

php中使用addslashes函数报错问题的解决方法

大家看下面的代码,能发现错误在哪里吗? 复制代码 代码如下:<?phpecho function_exists('addcslashes');//检测是否存在该函数echo get...

cmd下运行php脚本

其实蛮简单的 我的php安装目录在 d:\php 那么 运行 cmd >d: >cd php 要让工作目录指向php.exe的安装文件夹 然后就可以用php指令了 比如 在该...