2009-12-28 18 views
1

我正在使用以下代碼。我得到的錯誤:標題重定向和會話開始()生成錯誤

警告:不能更改頭信息 - 頭已經發出(輸出開始/home/public_html/mc/cpanel/Source/verifylogin.php:11)

警告:在session_start() function.session啓動]:不能發送會話cookie - 頭已經發出(輸出開始/home/public_html/mv/cpanel/Source/verifylogin.php:11)

警告:在session_start()[function.session -start]:無法發送會話緩存限制器 - 已發送的標頭(輸出開始於/home/public_html/mv/cpanel/Source/verifylogin.php:11)

<?php 
    error_reporting(E_ALL^ E_NOTICE); 
    ob_start(); 
    require("../Lib/dbaccess.php"); 

    $inQuery = "SELECT mhuserid, mhusername FROM cpanelusers WHERE mhusername = '". $_POST['UserName'] ."' AND mhpassword = '". hash('sha512', $_POST['Password']) ."'"; 

    try 
    { 
     $Result = dbaccess::GetRows($inQuery); 
     echo $Result; 
     $NumRows = mysql_num_rows($Result); 
     if ($NumRows > 0) 
     { 
      header("Location: http://www.example.com/cpanel/mainwindow.php"); 
      session_start(); 
     } 
     else 
     { 
      header("Location: http://www.example.com/cpanel/"); 
      echo "Last login attempt failed."; 
      exit; 
     } 
    } 
    catch(exception $e) 
    { 

    } 
    ob_clean(); 
?> 

我做了所有更改並減少了下面的代碼,但仍無法正常工作。

<?php 
    ob_end_clean(); 
    error_reporting(E_ALL^ E_NOTICE); 
    require("../Lib/dbaccess.php"); 
    ob_start(); 
    $inQuery="SELECT mhuserid, mhusername FROM cpanelusers WHERE mhusername = '".$_POST['UserName']."' AND mhpassword = '".hash('sha512', $_POST['Password'])."'"; 
    try 
    { 
     $Result=dbaccess::GetRows($inQuery); 
     $NumRows=mysql_num_rows($Result); 
     if ($NumRows>0) 
     { 
      header("mainwindow.php"); 
     } 
     else 
     { 
      header("index.html"); 
     } 
    } 
    catch(exception $e) 
    { 
    } 
?> 
+1

這必須是關於php的最常見問題 – Galen 2009-12-28 06:45:35

+0

它顯示了這些標題有多大的問題。 – RKh 2009-12-28 06:57:39

回答

0

找出問題所在。這是產生錯誤的「要求......」聲明。我添加了連接字符串和函數以在同一個文件中執行查詢。

1

session_start()和header()都要求沒有任何內容寫入頁面。您在第11行使用echo,從而將內容寫入頁面。

由於某種原因,您的ob_start似乎不起作用。也許輸出緩衝在您的PHP配置中被禁用?