2012-08-15 75 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(); 
} 
相关问题