我正在制作一个平面文件登录系统,当我单击 login.php 页面上的提交按钮时,它会转到 protected.php 并返回内部服务器错误,但是当我只是加载 protected.php 页面而不使用一切都很好。
登录.php
<html>
<link rel="stylesheet" type="text/css" href="style.css">
<body>
<center><img src="logo.png"></center>
<div id="login">
<form action="protected.php" method="post">
</br>
Username <input type="text" name="user" class="text"/>
<p></p>
Password <input type="password"" name="pass" class="text" />
<p></p>
<input type="submit" value="Login" class="button">
</form>
</div>
</body>
</html>
protected .php
<?php
$usr = "admin";
$pass = "admin";
$iusr = $_POST["user"];
$ipass = $_POST["pass"];
if ($iuser !== $usr || $ipass !== $ipass) {
?>
<html>
<script type="text/javascript">
<!--
window.location = "login.php"
//-->
</script>
</html>
<?php
}
?>
<html>
<link rel="stylesheet" type="text/css" href="style.css">
<body>
</body>
</html>
求助!提前致谢!
最佳答案
“内部服务器错误”可能意味着多种情况,但最有可能意味着您的 PHP 代码中存在错误。这需要在您的 php.ini 中将 display_errors
属性设置为“1”。该问题也可能是启动错误,因此您可能还希望考虑 display_startup_errors
属性。
http://www.php.net/manual/en/errorfunc.configuration.php#ini.display-errors
关于代码的两条评论,与您的问题无关:1) 表达式 $ipass !== $ipass
似乎是一个错字,因为它总是返回 FALSE
, 和 2) 通过关闭 javascript 很容易绕过这个“安全”。考虑改用 header()
进行重定向。
http://us2.php.net/manual/en/function.header.php
编辑: ... 在这种特定情况下,错误是使用了 undefined variable $iuser
。您之前将其声明为 $iusr
。打开错误报告或查看日志将为您提供很好的错误消息,以便您轻松找到此类问题。
关于PHP - 提交页面返回内部服务器错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13597925/