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?

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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++;
	//}
}
}

Link to comment
Share on other sites

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/

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.