I want to use glob()
in a php script, but I got reports from users that it's not always allowed on the server. One user reported the following error:
Warning: glob() has been disabled for security reasons
How do I detect whether glob is allowed? Is this done via disable_functions, or are there other ways glob can be disabled? Does safe_mode also disable glob? (one commenter on php.net says so).
Are there ways to reliably check if it's allowed other than checking safe_mode & disable_functions (as suggested in: how to test if PHP system() function is allowed? and not turned off for security reasons)
The glob()
function returns NULL
if it's disabled, so:
if (($res = glob('*')) === null) {
//try something else
} else {
// $res should be an array or false
}
Btw, this won't prevent a warning from showing up; you can choose to either silence or ignore it altogether.
AFAIK glob
can be only disabled using the disable_functions
ini setting. Use function_exists()
to detect if it is available:
if(function_exists('glob')) {
glob('...');
}
You can try it using this simple tests:
you@server ~ $ php -ddisable_functions='glob' -r 'var_dump(function_exists("glob"));'
bool(false)
you@server ~ $ php -r 'var_dump(function_exists("glob"));'
bool(true)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With