gpt4 book ai didi

PHP - 如何知道服务器是否允许 shell_exec

转载 作者:可可西里 更新时间:2023-11-01 12:30:52 25 4
gpt4 key购买 nike

在某些服务器上,不允许 PHP 通过 shell_exec 运行 shell 命令。如何检测当前服务器是否允许通过 PHP 运行 shell 命令?如何通过 PHP 启用 shell 命令执行?

最佳答案

首先检查它是否可调用,然后检查它是否被禁用:

is_callable('shell_exec') && false === stripos(ini_get('disable_functions'), 'shell_exec');

这种通用方法适用于任何内置函数,因此您可以将其通用化:

function isEnabled($func) {
return is_callable($func) && false === stripos(ini_get('disable_functions'), $func);
}
if (isEnabled('shell_exec')) {
shell_exec('echo "hello world"');
}

注意使用stripos,因为PHP函数名不区分大小写。

关于PHP - 如何知道服务器是否允许 shell_exec,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21581560/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com