2012-08-15 34 views
-3

可能重複:
「Warning: Cannot modify header information - headers already sent by」 error
Headers already sent by PHP不能更改頭信息 - 頭已經發出(輸出開始這是什麼意思

我已經看過許多其他網站?問題是由於白色的間距,我不認爲這是問題,因爲我的PHP腳本結束後,我的PHP腳本開始之前,我沒有留下任何白色的間距。這是完整的錯誤或

:不能更改頭信息 - 頭已經發出的admin/login.php中(輸出開始/admin/login.php:19)上線22

這裏是我的代碼:

 <?php 
     require_once("../../includes/database.php"); 
     require_once("../../includes/session.php"); 
     require_once("../../includes/user.php"); 

     if($session->is_logged_in()) 
     { 
     header("Location:index.php"); 
     } 
     if(isset($_POST['submit'])) 
     { 
     $username = trim($_POST['username']); 
     $password = trim($_POST['password']); 
     //Check Databases 
     $found_user = User::authenticate($username, $password); 
     $found_user->id = $found_user[0]; 
     if($found_user) 
     { 
      $session->login($found_user); 
      header("Location:index.php"); 
     } 
     else 
     { 
      echo "Username/password combination incorrect."; 
     } 
      } else { //form is not submitted 
     $username = ""; 
     $password = ""; 
     } 
     ?> 
     <html> 
      <head> 
      </head> 
      <body> 
      <h1>Photo Gallery</h1> 
      <div id="main"> 
      <h2>Staff Login</h2> 
      <form action="login.php" method="post"> 
      <table> 
     <tr> 
       <td>Username:</td> 
       <td> 
        <input type="text" name="username" maxlength="30" value="" /> 
       </td> 
      </tr> 
      <tr> 
       <td> Password:</td> 
       <td> 
        <input type="password" name="password" maxlength="30" value="" /> 
       </td> 
      </tr> 
      <tr> 
       <td colspan="2"> 
        <input type="submit" name="submit" value"Login" /> 
       </td> 
      </tr> 
      </table> 
      </form> 
      </div> 
      </body> 
      </html> 
      <?php if(isset($database)) 
     { 
       $database->close_connection(); 
     } 
      ?> 
+1

添加'出口();'每頭之後。 – MrYanDao 2012-08-15 02:57:01

+0

搜索是你的朋友...... – 2012-08-15 03:06:16

+0

只需從php.ini啓用output_buffering :) – 2012-08-15 05:50:31

回答

0

如果您使用的是header()來重定向用戶,請確保在header()呼叫後使用exit()明確停止腳本。否則,腳本會繼續嘗試輸出以下所有內容。

例如:

if($session->is_logged_in()) 
{ 
    header("Location:index.php"); 
    exit(); 
} 
相關問題