Domanda

I'm getting 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 fall back on something else), I'd like not to have this warning. The PHP application should run on different servers, some users will be able to add that path to their allowed open_basedir paths, but others won't have access to that configuration.

My first guess was to check readability with is_readable(), however, I'm still getting the warning.

The question: How do I check if a certain path or file has been added to the open_basedir paths?

È stato utile?

Soluzione

You can read the value of PHP directives with the ini_get() function:

ini_get('open_basedir')

If the directive's not empty, it should contain a string with one ore more paths separated by PATH_SEPARATOR.

Altri suggerimenti

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

If is_readable returns false then you know that it's not readable.

$readable = @is_readable(..);
if(!$readable) {
    ....not readable
}

file_exists emits a warning if directory is restricted. Let's 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 PHP 7.
    @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';
}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top