Jump to content

OPEN_BASEDIR restriction error :: logs and code here - online users function


BizLab

Recommended Posts

Here is my schnazzy users online "counter" that i worked up for my site. It will open the session save folder and count any unexpired (recently refreshed) sessions to give me an estimate of the number of users online. There is a small Regex in place to ensure that it only counts session files, in case anything else ends up in there.

 

define("MAX_IDLE_TIME", 3);
if ($handle = opendir(session_save_path())) {
    $count = 0;    
    while (false !== ($file = readdir($handle))) {
        if(preg_match('/^sess_\w+/', $file)){
            if(time()- fileatime(session_save_path() . '\\' . $file) < MAX_IDLE_TIME * 60){
                $count++;
            }
        }
    }
return $count;	
closedir($handle);
}

 

When running this script, i get the following error:

 


Warning: opendir() [function.opendir]: open_basedir restriction in effect. File(/var/www/vhosts/domain.com/tmp) is not within the allowed path(s): (/var/www/vhosts/domain.com/httpdocs:/tmp) in /var/www/vhosts/domain.com/httpdocs/admin/office/index.php  on line 107

Warning: opendir(/var/www/vhosts/domain.com/tmp) [function.opendir]: failed to open dir: Operation not permitted in /var/www/vhosts/domain.com/httpdocs/admin/office/index.php on line 107

 

Session Save path is (as found by running session_save_path()):

 

/var/www/vhosts/domain.com/tmp // session save path

 

I found a few mentions of bugs while searching around.. talking about leaving off the trailing '/' or not... but i tried both methods, and neither worked.

 

Any thoughts?

Have you tried using glob instead of opendir?

 

define("MAX_IDLE_TIME", 3);
$sessions = glob(session_save_path() . '/sess_*');
$count = 0;

foreach ($sessions as $session) {
  // do your expiry computation here...
}

 

Or you could always try changing the save path  ;)

 

HTH

mcdsoftware - I like the way you are thinking, this seems like it would run faster than the original. At this point, i have 4 sessions in the file, and when running this code, i receive an empty array. As you can see, i even commented out the time exipry criteria to see if anything will display. still nothing

 

define("MAX_IDLE_TIME", 3);
// check to see if there was a result, if not - assign an empty array to the variable
(glob(session_save_path()."/sess_*") ? $sessions = glob(session_save_path()."/sess_*") : $sessions = array());
$count = 0;
print_r($sessions);
if($sessions){
foreach ($sessions as $session) {
  // do your expiry computation here...
	//if(time()- fileatime($session) < MAX_IDLE_TIME * 60){
		$count++;
	//}
}
}

I just tested your code and it does list all my session files so it looks like it's working  :D. Try to check if you have read access to the tmp directory. Maybe try fopen-ing a session file to see if there will be any errors.

So while trying to open the /tmp/ directory i end up with the first open_basedir error. I tried to alter the open_basedir setting at runtime with the ini_set() function to allow only this script to access the directory, but that didn't work either.

 

The phpinfo shows the open_basedir to be set to:  /var/www/vhosts/domain.com/httpdocs:/tmp

 

i figure i need to back that down the path a little to the:  /var/www/vhosts/domain.com/ or even  /var/www/vhosts/domain.com/tmp/

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.