Is there any function in PHP that I can use to detect whether or not the exec
function is available?
views:
43answers:
2
+2
A:
<?php
function exec_enabled() {
$disabled = explode(', ', ini_get('disable_functions'));
return !in_array('exec', $disabled);
}
?>
UltimateBrent
2010-10-14 22:37:49
A:
You can search the ini setting disable_functions
for the exec()
function.
if( false !== strpos(ini_get("disable_functions"), "exec") ) {
// exec() is disabled
Just for completeness, note that PHP Safe Mode puts some restrictions on the function too.
svens
2010-10-14 22:41:44
Way too slow as I see :)
svens
2010-10-14 22:42:39
This will return the wrong answer if a function like `shell_exec` has been placed in `disable_functions` but `exec` has not. Best to use explode or regex to make sure it matches a complete function name.
webbiedave
2010-10-14 22:54:35
Whoops, that's correct.
svens
2010-10-14 23:03:32