I am writing an application where I want to allow some users to write / run / test their code on my server, with some preloaded code from my application. I want these users to be able to work only in their directory and this task can be done with open_basedir();
, but the problem is that if I want to include my application's code I get permission denied if the require
or include
is inside a function
or a class
so the file is not included before open_basedir
was called.
Example :
<?php
function test()
{
require 'test.php';
}
test(); // ok
ini_set('open_basedir', 'users/username/');
test(); // permission denied
Is it possible somehow to allow "trusted" code of the application to be included but don't allow the user's code to access another directories? And if it is possible, give me an example or the main idea on how I can resolve this, even if this is not related to the open_basedir()
In my example, I would like to not have the permission denied. This will give me possibility to add some great features to my application.
Another Example :
spl_autoload_register(function($class) {
require $class . '.php';
});
ini_set('open_basedir', 'folder/');
new Test(); // Warning: require(): open_basedir restriction in effect.