1

I am trying to solve this error related to session in php. please do help me. thankyou!

Warning: session_start(): Cannot send session cookie - headers already sent by (output started at C:\xampp\htdocs\myfolder\Login.php:117) in C:\xampp\htdocs\myfolder\Login.php on line 155

Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at C:\xampp\htdocs\myfolder\Login.php:117) in C:\xampp\htdocs\myfolder\Login.php on line 155

here is the php code:

$adm_user=$_POST['username'];
$adm_pass=$_POST['password'];
if($adm_user=="" || $adm_pass=="")
{
    echo'Fields Cannot Be Empty';
}
else
{
    $adm_login_sql="SELECT admin_login.username, admin_login.password
                    FROM admin_login
                    WHERE username='$adm_user' AND password='$adm_pass'";

    $adm_login_query=mysql_query($adm_login_sql);

    if (!$adm_login_query)
        {
        echo "Error: No records found" . mysql_error();
        }
    else
        {
            echo "query successful<br>";

            $adm_login_row=mysql_fetch_array($adm_login_query);

            $check_uname=$adm_login_row[0];
            $check_pass=$adm_login_row[1];


                if($check_uname==$adm_user && $check_pass==$adm_pass)
                {
                    session_start();
                    $_SESSION['name']=$adm_user;

                    header('location:admin.php');   
                }
                else
                {
                    echo 'Password Missmatch!!!';
                }

        }
}
Alive to die - Anant
  • 70,531
  • 10
  • 51
  • 98
Arun
  • 31
  • 4

2 Answers2

1

add @ob_start(); in first code line and change
session_start(); to @session_start();

Alive to die - Anant
  • 70,531
  • 10
  • 51
  • 98
paranoid
  • 6,799
  • 19
  • 49
  • 86
1

"Headers already sent" means that your PHP script already sent the HTTP headers, and as such it can't make modifications to them now.

Check that you don't send ANY content before calling session_start(). Better yet, just make session_start() the first thing you do in your PHP file (so put it at the absolute beginning, before all HTML etc).

Alive to die - Anant
  • 70,531
  • 10
  • 51
  • 98
Drudge Rajen
  • 7,584
  • 4
  • 23
  • 43