Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/243.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typo3/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
php exec()或安全模式下的相同函数_Php_Safe Mode - Fatal编程技术网

php exec()或安全模式下的相同函数

php exec()或安全模式下的相同函数,php,safe-mode,Php,Safe Mode,可能重复: 我的项目正在共享主机上运行,因此启用了安全模式。我想使用exec()函数,但不可能。在这种情况下我该怎么办? 是否有相同的功能或解决方案在安全模式下工作?此功能结合了我所知道的所有可能性。试试看。我希望,这会有帮助 <?php function _exec($cmd) { $disablefunc = array(); $disablefunc = explode(",", str_replace(" ", "", @ini_get("disable_func

可能重复:

我的项目正在共享主机上运行,因此启用了安全模式。我想使用exec()函数,但不可能。在这种情况下我该怎么办?

是否有相同的功能或解决方案在安全模式下工作?

此功能结合了我所知道的所有可能性。试试看。我希望,这会有帮助

<?php
function _exec($cmd) {
    $disablefunc = array();
    $disablefunc = explode(",", str_replace(" ", "", @ini_get("disable_functions")));
    if(is_callable("exec") && !in_array("exec", $disablefunc)) {
        exec($cmd, $result);
        $result = join("\n", $result)."\n";
    } elseif(is_callable("system") && !in_array("system", $disablefunc)) { 
        $src = @ob_get_contents();
        @ob_clean();
        system($cmd);
        $result = @ob_get_contents();
        @ob_clean();
        echo $src;
    } elseif(is_callable("passthru") && !in_array("passthru", $disablefunc)) {
        $src = @ob_get_contents();
        @ob_clean();
        passthru($cmd);
        $result = @ob_get_contents();
        @ob_clean();
        echo $src;
    } elseif(is_callable("popen") && !in_array("popen", $disablefunc) && is_resource($h = popen($cmd, "r"))) {
        $result = "";
        if(is_callable("fread") && !in_array("fread", $disablefunc)) {
            while(!feof($h)) {
                $result .= fread($h, 1024);
            }
        } else {
            while(!feof($h)) {
                $result .= fgets($h, 1024);
            }
        }
        pclose($h);
    } else {
        trigger_error("Cannot execute the command due to server restrictions.", E_USER_WARNING);
        return false;
    }
    return $result;
}

echo "<pre>"._exec("ls")."</pre>";
?>


移动主机。真的是最好的选择。许多共享主机都允许exec()和安全模式。这改变了问题,不是一个解决方案大多数好的主机都没有这个限制,所以这当然是一个解决方案。有数百万台主机,但并非所有主机都适合特定项目。如果他们以任何方式通过“代码”施加此限制,可能会违反他们的条款-因此无论如何都不是一个健壮的解决方案。这取决于您需要执行脚本的上下文。在启用安全模式的情况下,您不能从php执行它,但您可以通过其他方式执行它。