Check if open_basedir restriction applies

I get the following warning when using PHPass ( http://www.openwall.com/phpass/ ):

open_basedir restriction in effect. File(/dev/urandom) is not within the allowed path(s) 

Although this is not a big problem (it will return to something else), I would not want this warning. The PHP application must run on different servers, some users will be able to add this path to the allowed open_basedir paths, but others will not have access to this configuration.

My first assumption was to check readability with is_readable() , however, I still get a warning.

Question: How to check if a specific path or file has been added to the open_basedir path?

+8
php phpass open-basedir
source share
3 answers

You can read the meaning of PHP directives using the ini_get() function:

 ini_get('open_basedir') 

If the directive is not empty, it must contain a string with one or more paths , separated by PATH_SEPARATOR .

+3
source share

You can use is_readable and disable the warning for this function with @ .

If is_readable returns false, you know that it is not readable.

 $readable = @is_readable(..); if(!$readable) { ....not readable } 
+1
source share

file_exists gives a warning if the directory is limited. Let me use it:

 function isRestricted( $path ) { // Default error handler is required set_error_handler( null ); // Clean last error info. You can do it using error_clean_last in PHP7. @trigger_error( '__clean_error_info' ); // Testing... @file_exists( $path ); // Restore previous error handler restore_error_handler(); // Return `true` if error has occured return ($error = error_get_last()) && $error[ 'message' ] !== '__clean_error_info'; } 
0
source share

All Articles