检查“exec”是否有效已禁用
PHP 中是否有任何函数可以用来检测 exec 函数是否可用?
Is there any function in PHP that I can use to detect whether or not the exec
function is available?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
编辑:根据 Ziagl 的评论修复了爆炸。
EDIT: Fixed the explode as per Ziagl's comment.
下面的函数更加健壮。它处理函数名称之间有 0 个或多个空格的
disabled_functions
值,检查 suhosin 补丁的黑名单设置,覆盖safe_mode
,并存储答案以供将来参考。The following function is more robust. It deals with the
disabled_functions
value having 0 or more spaces between function names, checks the suhosin patch's blacklist setting, coverssafe_mode
, and stores the answer for future reference.您可以在 ini 设置
disable_functions
中搜索exec()
函数。为了完整起见,请注意 PHP 安全模式 放置了一些功能上也有限制。
You can search the ini setting
disable_functions
for theexec()
function.Just for completeness, note that PHP Safe Mode puts some restrictions on the function too.
您还需要检查 safe_mode 是否处于活动状态,因为如果 safe_mode 处于打开状态,则 exec 不可用
You also need to check whether safe_mode is active as exec is unavailable if safe_mode is on
使用在各种 SO 帖子中找到的一些技术,对安全模式、函数存在和禁用 exec 进行了单行编译。
这将在尝试运行之前检查 exec 是否可用并已启用。如果运行 exec() 并且该函数不存在或被禁用,则会生成警告。根据可能呈现给浏览器的服务器设置,并且几乎总是将一行写入日志文件=性能影响。
A one-line compilation of safe mode, function exists, and disabled exec using some of the techniques found on various SO posts.
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.