我可以在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