Check If "Exec" Is Disabled

PHP exec - check if enabled or disabled

if(function_exists('exec')) {
echo "exec is enabled";
}

Check if exec is disabled

<?php
function exec_enabled() {
$disabled = explode(',', ini_get('disable_functions'));
return !in_array('exec', $disabled);
}
?>

EDIT: Fixed the explode as per Ziagl's comment.

exec function is not working in PHP

okay, it was a file permission issue. www-data had not the permission to write the file, after changing the permission it's working now.

PHP - How to know if server allows shell_exec

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"');
}

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



Related Topics



Leave a reply



Submit