, , ( - ).
token_get_all() , T_ECHO T_PRINT ( ). -, , (eval(), , :// ..). .
T_INCLUDE, T_INCLUDE_ONCE, T_REQUIRE T_REQUIRE_ONCE. (, PHP, , ), .
PHP ADB, , . , , . , set_cookie() header(), . - , , .
class YourApplicationControllingClass {
final protected function callUserCode($pathToUserCodeFile) {
$suspender = new SuspendFunctions();
ob_start();
$suspender->suspend("ob_clean", "ob_end_clean", "ob_end_flush", "ob_flush",
"ob_get_clean", "ob_get_contents", "ob_get_flush", "ob_get_length",
"ob_get_level", "ob_get_status", "ob_implicit_flush", "ob_list_handlers",
"ob_start", "output_add_rewrite_var", "output_reset_rewrite_vars",
"set_cookie", "set_raw_cookie", "header_register_callback", "header",
"header_remove", "http_response_code", "register_shutdown_function",
"register_tick_function", "unregister_tick_function", "set_error_handler",
"restore_error_handler", "set_exception_handler", "restore_exception_handler"
);
$this->callUserCodeSandbox($pathToUserCodeFile);
$suspender->resume();
$content = ob_get_clean();
if ($content !== '') $this->blacklistUserCode($pathToUserCodeFile);
}
private function callUserCodeSandbox($pathToUserCodeFile) {
require($pathToUserCodeFile);
}
}
final class SuspendFunctions {
private $suspendedFunctions = array();
function suspend($function) {
$functions = func_get_args();
foreach($functions as $function) {
if (isset($this->suspendedFunctions[$function])) continue;
$newName = '_'.md5($function.microtime(true).mt_random());
rename_function($function, $newName);
$this->suspendedFunctions[$function] = $newName;
}
}
function resume() {
foreach($this->suspendedFunctions as $function=>$newName) {
rename($newName, $function);
unset($this->suspendedFunctions[$function]);
}
}
}