PHP sessions unknown error
<p>I have a website that contains a login and when the user is logged in I want it to display a message on the main page as well as carry the session on through.</p>

<p>I am receiving the error:</p>

<pre><code>Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by..
</code></pre>

<p>and </p>

<pre><code>Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent
</code></pre>

<p>When I am not logged in it displays the error, but as soon as I log in and return to the page it disappears, but doesn't display the "You are logged in!" like it should...</p>

<p>Here is my authentication code after it checks the database for a match:</p>

<pre><code>if ($result["userName"] == $_POST[txtUsername] &amp;&amp; $result["password"] ==$_POST[txtPassword])
    {
        ?&gt;
        &lt;script type="text/javascript"&gt;;
        alert("successfully logged in, &lt;?php echo $result['userName'];?&gt;!");
        window.location.href='http://manning3.jcu.edu.au/~jc192699/index.html';
        &lt;/script&gt;
        &lt;?php
        session_start();
        $_SESSION["access"] = 'granted';
    }
</code></pre>

<p>And my code in my index.php that seems to cause the error:</p>

<pre><code> &lt;?php
    session_start();
    if ($_SESSION["access"] == 'granted'){
        ?&gt;
        &lt;p&gt;You are logged in!&lt;/p&gt;
        &lt;?php
    }
    else{
    ?&gt;
    &lt;p&gt;You are not logged in!&lt;/p&gt;
    &lt;?php
    }
    ?&gt;
</code></pre>

<p>Any help would be GREATLY appreciated. Thank you!</p>
