tags:

views:

61

answers:

3

I am using following code. I get errors:

Warning: Cannot modify header information - headers already sent by (output started at /home/public_html/mc/cpanel/Source/verifylogin.php:11)

Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /home/public_html/mv/cpanel/Source/verifylogin.php:11)

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /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();
?>
+1  A: 

Both session_start() and header() requires that nothing have been written to the page. You are using echo on row 11, thus writing things to the page.

For some reason your ob_start doesn't seem to work. Maybe output buffering is disabled in your PHP configuration?

Emil Vikström
A: 

I did all the changes and reduced the code like below, still it is not working.

<?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)
    {
    }
?>
RPK
A: 

Figured out the problem. It was the "require..." statement that generated errors. I added the connection string and the function to execute the query in the same file.

RPK