2012-11-28 57 views
1

我正在製作一個平面文件登錄系統,當我單擊提交login.php頁面上的按鈕時,它會轉到protected.php並返回內部服務器錯誤,但是當我只是加載這個protected.php頁面而不使用表單,事情變得很好。PHp - 提交頁面返回內部服務器錯誤

的login.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> 

請幫幫忙!提前致謝!

+1

有關錯誤的有趣之處在於它們通常帶有某種消息。檢查你的錯誤日誌 – Phil

回答

2

「內部服務器錯誤」可能意味着幾件事情,但最有可能意味着您的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

編輯: ...在這種特定情況下,錯誤是使用可變$iuser,這是不確定的。您之前已將其宣佈爲$iusr。打開錯誤報告或查看日誌會爲您提供良好的錯誤消息,以輕鬆找到這些問題。

0

的login.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="password" class="text" /> 
     <p></p> 
      <input type="submit" name="submit" value="Login" class="button"> 
     </form> 
    </div> 
</body> 

protected.php

<?php 
$usr = "admin"; 
$pass = "admin"; 

$iusr = $_POST["user"]; 
$ipass = $_POST["password"]; 
if(isset($_POST["submit"])){ 
if ($iusr != $usr || $ipass != $pass) { 
?> 
<html> 
<script type="text/javascript"> 

window.location = "login.php" 

</script> 
</html> 
<?php 
}} 
?> 
<html> 
<link rel="stylesheet" type="text/css" href="style.css"> 
<body> 

</body> 

0

的問題是在你的protected.php文件,你已經寫了一個錯誤的狀態代碼具有($iuser !== $usr應該if ($iusr !== $usr || $ipass !== $pass) {還條件$ipass !== $ipass應該像$ipass !== $pass下面是updat ed protected.php文件

<?php 
$usr = "admin"; 
$pass = "admin"; 

$iusr = $_POST["user"]; 
$ipass = $_POST["pass"]; 

if ($iusr !== $usr || $ipass !== $pass) { 
    ?> 
    <html> 
     <script type="text/javascript"> 
      window.location = "login.php" 
     </script> 
    </html> 
    <?php 
} 
?> 
<html> 
    <link rel="stylesheet" type="text/css" href="style.css"> 
    <body> 
     Login success 
    </body> 
</html> 
相關問題