34107-vm/sandbox.php
2025-09-16 16:54:43 +00:00

19 lines
483 B
PHP

<?php
function execute_php_code($code) {
// Ensure the code is wrapped in PHP tags
if (strpos(trim($code), '<?php') !== 0) {
$code = '<?php ' . $code . ' ?>';
}
$descriptorspec = [
0 => ["pipe", "r"], // stdin
1 => ["pipe", "w"], // stdout
2 => ["pipe", "w"] // stderr
];
$process = proc_open('php', $descriptorspec, $pipes);
if (is_resource($process)) {
fwrite($pipes[0], $code);
fclose($pipes[0]);