This is my header.html file:

<?php
ob_start();
session_start();
if (!isset($page_title)) {
	$page_title = 'Welcome';
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/2000/REC-xhtml1-20000126/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
...

When i try to include it in my php files i get the following error:
Warning: session_start(): Cannot send session cookie - headers already sent by...

Anybody knows the reason?

    there is no need for ob_start() if you are placing session_start() at the top of the page.

      That's nearly always because you have sent some output to the browser before you call session_start(), even a space will cause it to spit out this error.

        i tried using only
        <?php
        session_start();
        ?>

        but i still get the same error. I checked for extra spaces but i'm pretty sure there are no spaces. what else could be wrong? Could it be something from my php file which includes this header file?

        My php file starts like this:
        <?php
        include ('header.html');
        ...

          Make sure there is not even a space before <?php... because even that is output and will cause the error (believe it or not this has been known to happen) a little space before the greater than sign in you file is all it takes.

            Then what does the full

            Warning: session_start(): Cannot send session cookie - headers already sent by...

            say what file is it yelling about, does that file have any output before it calls the new session?

              there got be some output either before

              <?php
              session_start();
              ?>

              in your header.html

              or some output before

              <?php
              include ('header.html');
              ...

              in your including file

                Insure to use .php instead of .html

                <?php
                session_start();
                include("header.php");
                
                // internal content
                
                include("footer.php");
                ?>

                  I had this same problem about 6 months ago..If you are using dreamweaver I suggest that you open the file in notepad or similar and check for any characters/spaces/etc before your <?php tags....Sometimes dreamweaver will put hidden characters before your tags.

                  Let us know if it works! 🙂

                    I forgot about how some WYSIWYG's doing things like that, I don't use DW myself just PHP Designer or HTML kit but it is entirely within reason that opening the file in DW might not show anything and using notepad will.

                    Maybe they should be called WYSINEWYG (What you see is not exactly what you get).

                      And make sure you check all files for data before the opening php tag - that means the include file and the script that's calling it.

                        OK. Finally i got this stupid thing resolved!! For sure WYSINEWYG (What you see is not exactly what you get), or maybe i could say what you don't see is exactly what you get!! :rolleyes:

                        In dreamweaver and notepad i couldn't see anything weird. Then i had a look at my php file with an editor which is part of the H-Sphere software used by my hosting company, and just before the opening <?php of my index.php i saw some characters that shouldn't be there. As soon as i removed those characters the problem resolved! I had a look at all my files (created with dreamweaver) and those characters are always there, but i can only see them with the specific editor. That really sucks, so for any people that maybe face this problem in the future, just try viewing the files with some other editors as not all of them can display those characters.

                        Thank you all guys for your help! 🙂

                          If you can get you hands on a copy, try using Adobe GoLive. It only places in what you place in there.

                          Insure to " mark as resolve" your thread

                            Write a Reply...