0

我有这段代码来检查用户输入的登录信息,当信息正确时,它应该显示下一页,它不应该显示一个显示“未找到用户”的页面,事情就是这样上传我的网站后代码工作正常,但我收到此错误:

[18-May-2012 15:07:31] PHP Warning: session_start() [<a href='function.session-start'>function.session-start</a>]: Cannot send session cookie - headers already sent by (output started ....)"

并且当我搜索时,我知道这发生在会话之前会导致一些输出,所以我修复了它,但是当我修复并输入错误信息时,它只显示空白页!任何帮助将不胜感激这是代码:

<?php
ob_start();
session_start();
include("adBanner.html");
echo "<br />
<br />
<br />
<br />
<br />
<br />
";
// Connect to server and select databse.
$con = mysql_connect('localhost', 'root', 'pass')or die("cannot connect");
$sel = mysql_select_db('drsaada1_iexa',$con)or die("cannot select DB");
// username and password sent from form
$myusername = addslashes(strip_tags($_POST['myusername']));
$mypassword = addslashes(strip_tags($_POST['mypassword']));
if ($myusername && $mypassword){
  $finduser = mysql_query("SELECT * FROM instructor WHERE Name='".$myusername."' and     Password='".$mypassword."'")
  or die ("mysql error");
  if (mysql_num_rows($finduser)!=0){
    while ($row = mysql_fetch_assoc($finduser)){
      $uname = stripcslashes($row['Name']);
      $upass = stripcslashes($row['Password']);
    }
    if ($myusername == $uname AND $mypassword == $upass){
        $_SESSION['sessionname']= $uname ;
        $_SESSION['sessionpass']= $upass ;
        echo '<h3>Welcome '.$uname.' To iExamination System</h3> <br />
        <a href="Instructor.htm"><h2>Go To Instructor Page</h2></a>
        ';
    }
  }
//////////
 $findadmin = mysql_query("SELECT * FROM admin WHERE Username='".$myusername."' and     Password='".$mypassword."'")
  or die ("mysql error");
  if (mysql_num_rows($findadmin)!=0){
    while ($row = mysql_fetch_assoc($findadmin)){
      $iname = stripcslashes($row['Username']);
      $ipass = stripcslashes($row['Password']);
    }
    if ($myusername == $iname AND $mypassword == $ipass){
        $_SESSION['sessionna']= $iname ;
        $_SESSION['sessionpa']= $ipass ;
        echo '<h3>Welcome '.$iname.' To iExamination System</h3> <br />
        <a href="admin.htm">Go To Adminstrator Page</a>
        ';
    }
  }

}else {
  die ("Not Fouund User Or Page ");
}


mysql_close($con);
ob_end_flush();
?>
4

1 回答 1

1

您死在缓冲区内,因此将看不到任何输出。如果你要死了,你需要先ob_end_clean()缓冲区。

于 2012-05-20T02:31:36.963 回答