PHP-如何知道服务器是否允许shell_exec [英] PHP - How to know if server allows shell_exec

查看:93
本文介绍了PHP-如何知道服务器是否允许shell_exec的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

On some servers, PHP is not allowed to run shell commands via shell_exec. How can I detect if current server allows running shell commands via PHP or not? How can I enable shell commands execution via PHP?

推荐答案

首先检查它是否可调用,然后再将其禁用:

First check that it's callable and then that it's not disabled:

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

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

This general approach works for any built in function, so you can genericize it:

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函数名称不区分大小写.

Note to use stripos, because PHP function names are case insensitive.

这篇关于PHP-如何知道服务器是否允许shell_exec的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆