我可以在MAMP上完美执行代码,但不能在我的hostgator服务器上执行。在服务器上,文本会自动转义以防止执行。为什么此PHP代码在localhost上工作,但不在共享主机上工作?
<?php
if (@isset($_POST['code'])) {
@$code = $_POST['code'];
@eval($code);
}
?>
<head>
<style>
textarea{
font-family: verdana;
font-size:20px;
color: #2799a0;
}
input[type="submit"] {
width: 200px;
height: 100px;
font-size: 30px;
}
</style>
<title>PHP Playground</title>
</head>
<form action="playground.php" method="POST">
<textarea name="code" cols="100" rows="20"><?php echo $_POST['code']; ?></textarea><br><br>
<input type="submit" value="Execute">
</form>
不要在用户输入中使用'eval'!根本不要使用'eval'。您允许用户在服务器上注入任意PHP,这就是为什么大多数托管提供商会禁用它。 – andho 2013-02-19 02:43:40
这只是个人用于测试脚本而不处理安装程序,我不够天真,无法将其上传到生产服务器。 – 2013-02-19 02:45:21
如果你想调试你的代码,不要在行前添加'@'来抑制错误和警告。 – Raptor 2013-02-19 02:46:25