Jump to content

session_start() [function.session-start]: Cannot send session cookie - headers a


ra_ie_darkness
 Share

Recommended Posts

I am trying to create an index page which contains registration and login field

the problem that i get is on successful login a warning is displayed

session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at C:\xampp\htdocs\Eventz.com\index.php:116) in C:\xampp\htdocs\Eventz.com\index.php on line 235

 

This is the login part of my index.php

this tag is inside an html table below the login form

I also have a registration form and its php code above the login form

 

 

<?php
if (isset($_REQUEST['pass']))
{
    $id=$_POST['id'];
    $pass=$_POST['pass'];

    $conn	=mysql_connect("localhost","root","");
    if (!$conn)
    {
   die('Could not connect: ' . mysql_error());
    }
/*
checking connection....success!
*/
    $e=mysql_select_db('test', $conn);
    if(!$e)
    {
   die(''.mysql_error());
    }
    else
    {
   echo 'database selected successfully';
    }

    if (isset($_REQUEST['id'])  || (isset($_REQUEST['pass'])))
    {
        if($_REQUEST['id'] == "" || $_REQUEST['pass']=="")
        {
       echo "login fields cannot be empty";
        }
        else
        {
            $sql=mysql_query("Select email,password from login where email='$id' AND password='$pass'");
            $count=mysql_num_rows($sql);
            if($count==1) 

    /* $count checks if username and password are in same row */
            {   
                session_start();
                $_SESSION['id']=$id;
                echo "</br>Login Successful</br>";
            }
            else
            {
           echo "</br>invalid</br>";
           echo "please try to login again</br>";

            }
        
        }   
    }
}
?>

 

 

Any help or suggestion would be appreciated

Link to comment
Share on other sites

this tag is inside an html table below the login form

 

I take it that means there is HTML above this block of PHP code?  You can't call session_start after you have sent output (which includes anything, even blank space) which is outside of <?php ?> tags.  Reason is session-start() has to send headers for the cookie, and sending output causes the headers to be sent which means you can't send any new headers after that point.

 

You need to move your processing code to be at the top of the script, before any other output.

 

see also, the sticky on header errors

Link to comment
Share on other sites

This thread is more than a year old.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.