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
Laravel Model Callbacks After Save, Before Save, etc
PHP - Returning the Last Line in a File
Transfer Variables Between PHP Pages
PHP Warning: Exec() Unable to Fork
MySQL Error When Inserting Data Containing Apostrophes (Single Quotes)
MySQL Encryption/Storing Sensitive Data,
Which MySQL Datatype to Use for an Ip Address
How Would I Implement a Simple Site Search with PHP and MySQL
Memory_Get_Peak_Usage() with "Real Usage"
PHP Date Add 5 Year to Current Date
Php: Do Arrays Have a Maximum Size
How to Display Special Characters in PHP
JavaScript Function Post and Call PHP Script
Mysql_Real_Escape_String Is Undefined
Pdo Returning Incorrect, But Duplicate, Data. Key's Not in Database
Ftp_Put Is Corrupting My Movies After Transfer, Is It Wrong