PHP exec - 检查是否启用或禁用
有没有办法检查 php 脚本是否在服务器上启用或禁用 exec()
?
Is there a way to check in a php script if exec()
is enabled or disabled on a server?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(10)
这将检查该功能是否确实有效(权限、权利等):
This will check if the function actually works (permissions, rights, etc):
ini_get('disable_functions')
您真正想要做的是使用
ini_get('disable_functions')
来了解它是否可供您使用:在 stackoverflow 上回答如下:< a href="https://stackoverflow.com/questions/3938120/check-if-exec-is-disabled">检查“exec”是否被禁用,这实际上似乎来自 PHP 手册页: http://php.net/manual/en/function.exec.php#97187
Path
如果上面返回 true(您可以使用 exec()),但 PHP 仍然无法触发脚本,则很有可能您的脚本存在路径问题,请测试这样做:
然后尝试
ini_get('disable_functions')
What you actually want to do is use
ini_get('disable_functions')
to find out if it is available to you:Answered on stackoverflow here: Check if "exec" is disabled, Which actually seems to come from the PHP Man page: http://php.net/manual/en/function.exec.php#97187
Path
If the above returns true (you can use exec()), but PHP can still not trigger the script there is a good chance that you have a path issue for that script, test this by doing:
and then try
这将在尝试运行之前检查 exec 是否可用并已启用。如果运行 exec() 并且该函数不存在或被禁用,则会生成警告。根据可能呈现给浏览器的服务器设置,并且几乎总是将一行写入日志文件=性能影响。
This will check that exec is available and enabled BEFORE trying to run it. If you run exec() and the function does not exist or is disabled a warning will be generated. Depending on the server settings that may render to the browser and will almost-always write a line to a log file = performance hit.
找到可用的
exec
函数有点棘手,除非检查所有可能性1.
function_exist('exec')
2.扫描
ini_get('disabled_functions)
3.检查
safe_mode
已启用除非
ini_get
函数未禁用,否则此函数绝不会引发警告。It's a bit tricky to find
exec
function available until unless checking all possibilities1.
function_exist('exec')
2.Scanning through
ini_get('disabled_functions)
3.Checking
safe_mode
enabledThis function never throws warnings unless
ini_get
function not disabled.我假设您正在 Linux 服务器上运行它。
您可以通过运行以下 php 脚本来测试 exec 函数:
这将返回命令 whoami。
如果出错,则是因为exec函数无法运行。
I am assuming that you are running this on a linux server.
You could test the exec function by running the following php script:
This will return the command whoami.
If it errors out, it is because the exec function could not run.
例子:
Example:
这是我编写的一些丑陋的代码,用于检测某个功能是否启用。
This is some ugly code I made to detect if a function is enabled or not.
(基于其他回复)
要检查 exec 是否存在并且服务是否正在运行:
(Based on other responses)
To check if exec exists and services are running:
我会用这个:
I would use this: