1
votes

I'm trying to use Sessions with PHP and I started them with session_start(); at the beginning of my index.php but got following error messages:

Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /home/ideal906/public_html/index.php:1) in /home/ideal906/public_html/index.php on line 2

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/ideal906/public_html/index.php:1) in /home/ideal906/public_html/index.php on line 2

This is strange has it's the very first line of my website:

<?php
    session_start();
?>

<!DOCTYPE html>
<html>
    <head>
<meta charset="utf-8" />
        <meta name="author" content="Pierre Anken">
        <meta name="description" content="Outil de création de menus équlibrés selon vos besoins">
        <!--[if lt IE 9]>
        <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
        <![endif]-->
        <script src="jquery.js"></script>
        <script src="scripts.js"></script>
        <link rel="stylesheet" href="style.css" />
        <title>Composez vos menus</title>
    </head>
    <body>
        <section id='sectionCentre'>
            <div id='presentation'>
                <h2>Ideal Menu</h2>

            </div>
        </section>
        <section id='bandeauHautDoite'>
            <nav>
                <ul>
                    <a href='#' elementMenu='monCompte' id='monCompte'>Mon compte</a><br/>
                    <a href='#' elementMenu='mesMenus' id='mesMenus'>Mes menus</a><br/>
                    <a href='#' elementMenu='mesRepas' id='mesRepas'>Mes repas</a><br/>
                    <a href='#' elementMenu='contact' id='contact'>Contact</a><br/>
                </ul>
            </nav>
        </section>
    </body>
</html>
1
You have output somewhere, otherwise the headers wouldn't be sent. Are you sure there's no whitespace before the starting PHP tag, and there's no other files being called but this one. - adeneo
Try removing the whitespace after the closing tag too. - user3111737
yep, verified, no whitespace, and nothing before. - Pierre Anken
Check in a hex-editor (or similar) to see if you have an invisible BOM before your <?php. Some editors place this at the start of files when saving as UTF-8. - borrible
^^^ Was just typing that, make sure it's not saved with a byte order mark. - adeneo

1 Answers

5
votes

You have an (invisible) BOM (byte-order-mark) that has been placed by your editor at the start of the file. It is being output before session_start() thus making your page unable to change the HTTP headers. Remove the BOM and the problem will go away.