125 lines
4.9 KiB
PHP
125 lines
4.9 KiB
PHP
<?php
|
|
|
|
function execute_php_code($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]);
|
|
|
|
$stdout = stream_get_contents($pipes[1]);
|
|
fclose($pipes[1]);
|
|
|
|
$stderr = stream_get_contents($pipes[2]);
|
|
fclose($pipes[2]);
|
|
|
|
proc_close($process);
|
|
|
|
return ['stdout' => $stdout, 'stderr' => $stderr];
|
|
}
|
|
return false;
|
|
}
|
|
|
|
$code = '';
|
|
$result_output = '';
|
|
$result_error = '';
|
|
|
|
if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
|
$code = $_POST['code'] ?? '';
|
|
if (!empty($code)) {
|
|
$execution_result = execute_php_code($code);
|
|
if ($execution_result !== false) {
|
|
$result_output = $execution_result['stdout'];
|
|
$result_error = $execution_result['stderr'];
|
|
} else {
|
|
$result_error = "Failed to execute the code.";
|
|
}
|
|
} else {
|
|
$result_output = "No code to run.";
|
|
}
|
|
}
|
|
|
|
?>
|
|
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>PHP Sandbox - Flatlogic LAMP Demo</title>
|
|
<meta name="description" content="Safely run PHP code snippets in an isolated environment.">
|
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
|
|
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.5/font/bootstrap-icons.css">
|
|
<link rel="stylesheet" href="assets/css/custom.css?v=<?php echo time(); ?>">
|
|
</head>
|
|
<body class="d-flex flex-column min-vh-100">
|
|
|
|
<nav class="navbar navbar-expand-lg navbar-light bg-white shadow-sm">
|
|
<div class="container">
|
|
<a class="navbar-brand" href="index.php">
|
|
<i class="bi bi-box-seam"></i>
|
|
Flatlogic<span style="color: #6366F1;">Vibes</span>
|
|
</a>
|
|
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
|
|
<span class="navbar-toggler-icon"></span>
|
|
</button>
|
|
<div class="collapse navbar-collapse" id="navbarNav">
|
|
<ul class="navbar-nav ms-auto">
|
|
<li class="nav-item"><a class="nav-link" href="index.php">Home</a></li>
|
|
<li class="nav-item"><a class="nav-link" href="vibe.php">Vibe Generator</a></li>
|
|
<li class="nav-item"><a class="nav-link active" href="sandbox.php">PHP Sandbox</a></li>
|
|
<li class="nav-item"><a class="nav-link" href="seo.php">SEO Checker</a></li>
|
|
<li class="nav-item"><a class="nav-link" href="admin.php">Admin</a></li>
|
|
</ul>
|
|
</div>
|
|
</div>
|
|
</nav>
|
|
|
|
<main class="container my-5">
|
|
<div class="text-center">
|
|
<h1 class="display-5">PHP Sandbox</h1>
|
|
<p class="lead col-lg-8 mx-auto">Test your PHP code snippets in a safe, isolated environment. Type your code, hit run, and see the output instantly.</p>
|
|
</div>
|
|
|
|
<div class="row mt-5">
|
|
<div class="col-lg-10 mx-auto">
|
|
<form action="sandbox.php" method="post">
|
|
<div class="mb-3">
|
|
<label for="code" class="form-label">PHP Code</label>
|
|
<textarea class="form-control font-monospace" id="code" name="code" rows="10" placeholder="<?php echo 'Hello, World!'; ?>"><?php echo htmlspecialchars($code); ?></textarea>
|
|
</div>
|
|
<button type="submit" class="btn btn-primary">
|
|
<i class="bi bi-play-fill"></i> Run Code
|
|
</button>
|
|
</form>
|
|
|
|
<?php if ($_SERVER["REQUEST_METHOD"] == "POST"): ?>
|
|
<div class="mt-4">
|
|
<h3>Output</h3>
|
|
<pre class="bg-light p-3 rounded"><code><?php echo htmlspecialchars($result_output); ?></code></pre>
|
|
|
|
<?php if (!empty($result_error)): ?>
|
|
<h3>Errors</h3>
|
|
<pre class="bg-danger text-white p-3 rounded"><code><?php echo htmlspecialchars($result_error); ?></code></pre>
|
|
<?php endif; ?>
|
|
</div>
|
|
<?php endif; ?>
|
|
</div>
|
|
</div>
|
|
</main>
|
|
|
|
<footer class="py-4 mt-auto bg-light">
|
|
<div class="container text-center">
|
|
<p class="mb-0 text-muted">© <?php echo date("Y"); ?> Flatlogic. All rights reserved.</p>
|
|
</div>
|
|
</footer>
|
|
|
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
|
|
<script src="assets/js/main.js?v=<?php echo time(); ?>"></script>
|
|
</body>
|
|
</html>
|