如何在PHP中保护php在线编辑器?

时间:2015-12-01 05:54:32

标签: php security editor disabled-input

我使用文件功能创建了一个php编辑器,用户可以在线运行代码并在同一页面上获得结果。

executephp5.php

<form action="<?php echo $_SERVER['PHP_SELF'];?>"method="post">
  <b>Write your code here</b>
  <textarea name="code"></textarea>
  <input type="submit"value="Run code">
</form>
<?php
$cd=stripslashes($_POST['code']);
#dont write empty textarea
if(empty($cd)) {
  echo "";
} else {
  $file=fopen("demo.php","w");
  echo fwrite($file, $cd);
  fclose($file);
}
?>

<b>Results:</b>
<hr>
<?php
  error_reporting(E_ALL);
  include "demo.php";
?>

demo.php是表单更新的目标文件。

这一切都按预期工作。我的问题是我要禁用此编辑器的所有文件,目录,mail()和ftp函数,以便用户不会崩溃网站。

有没有办法只为我的编辑器禁用这些功能?

1 个答案:

答案 0 :(得分:1)

您可以传入disable_functions,即&#34;逗号分隔的函数列表,以便在沙盒子解释器中禁用。&#34;

检查Runkit_Sandbox。您应该将编辑器设置为沙箱。