Header redirect and Session start() generating errors

Posted by RPK on Stack Overflow See other posts from Stack Overflow or by RPK
Published on 2009-12-28T05:47:56Z Indexed on 2012/03/28 5:29 UTC
Read the original article Hit count: 119

Filed under:
|

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();
?>

© Stack Overflow or respective owner

Related posts about php

Related posts about php5