How to check if PHP system () function is allowed? and not disabled for security reasons

I would like to know how to check if server () () or exec () is allowed on the server. I keep getting this error "Warning: exec () is disabled for security reasons in ..."

I understand that the safe_mode function is depreciating in the php version launched by my provider (5.3.3), so I cannot use the get_ini check ('safe_mode').

What else to do?

I use this for backup script. if the provider permits the system, the script makes a tar file and sends it to me when the user logs in.

Thanks in advance.

+4
source share
4 answers

Well, there are only two ways to disable it: safe_mode or disable_functions .

So you can check, for example:

 function isAvailable($func) { if (ini_get('safe_mode')) return false; $disabled = ini_get('disable_functions'); if ($disabled) { $disabled = explode(',', $disabled); $disabled = array_map('trim', $disabled); return !in_array($func, $disabled); } return true; } 

Oh and function_exists should return true, since this is the main function (otherwise you could create the main function and cause some real chaos on the host). Therefore, is_callable should also return true (since the function exists). So the only ways to say this is to check ini settings or actually call it ...

Edit: Another note: there are several ways to execute shell commands. Departure:

+9
source

Testing disabled features and having the safe mode shown by @ircmaxell is probably the easiest way.

If you want to know 1000% reliably whether it is possible to execute system commands - there may be security fixes like Suhosin that block it at another level - try exec() external command that must work on all systems (including Windows), and it is highly unlikely that it will fail, even if the user rights are very dense.

Let's say

 cd . 

this should work (i.e. not return false and return error code 0 ) in at least all versions of Linux, Windows and Unix, including OS X.

+3
source

function_exists () not working for this situation?

http://fr.php.net/function_exists

0
source

exec () returns false if it fails, or a successful message string if it succeeds ... so the following should work:

 if(!exec('cd .')){ die('ERROR: Exec is not available!!!'); } 

Replacement for 'cd.' can be any function that you know to work in the system.

0
source

All Articles