php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #20742 function to check if dir is allowed through open_basedir-directive
Submitted: 2002-12-01 02:51 UTC Modified: 2013-10-28 07:48 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: bugs dot php at jensthebrain dot de Assigned: krakjoe (profile)
Status: Closed Package: *General Issues
PHP Version: 4.2.3 OS: Linux
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: bugs dot php at jensthebrain dot de
New email:
PHP Version: OS:

 

 [2002-12-01 02:51 UTC] bugs dot php at jensthebrain dot de
I needed to check, whether a directory is allowed through open_basedir..
This should be in the php-functions.

My solution (not tested under windows):

function inOpenBasedir($dir) {
    $openBasedir = ini_get('open_basedir'); 
    if (empty($openBasedir)) { 
        return true; 
    } 

    foreach (explode(':', $openBasedir) as $basedir) 
    { 
	if( strlen($basedir) > strlen($dir) )
	{
	    // Check, if only a '\' is needed at the end of $dir
	    if( $basedir == ($dir . "/") )
	    {
		return true;
	    }
	}
	else
	{
	    // Check if basedir and dir are the same..
	    if( $basedir == $dir )
	    {
		return true;
	    }
	    else
	    {
		// open_basedir can be a prefix -> checking whether
		// dir starts with basedir or not
		if( strncmp($basedir, $dir, strlen($basedir)) == 0)
		{ 
		    return true; 
		} 
				    
	    }
	}	
    }
    return false; 
}

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-10-28 07:48 UTC] krakjoe@php.net
-Status: Open +Status: Closed -Package: Feature/Change Request +Package: *General Issues -Assigned To: +Assigned To: krakjoe
 [2013-10-28 07:48 UTC] krakjoe@php.net
This just doesn't belong, your application should work regardless of open_basedir.

Closing the request.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sun Nov 30 10:00:01 2025 UTC