PHP会话新手,错误[重复]

This question already has an answer here:

so I am attempting to use sessions... I get this error:

Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /home1/####/public_html/####/index.php:3) in /home1/####/public_html/####/index.php on line 4

index.php:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<?php
    session_start();
    echo $_SESSION['logged_in'];
    echo $_SESSION['logged_user'];
?>
<head>

Any Idea why this might be happening?

</div>

Once you output HTML, or any content, PHP can no longer send the headers required to use sessions (i.e. set cookies). You must call session_start() before any output is generated from your script:

<?php
    session_start();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<?php
    echo $_SESSION['logged_in'];
    echo $_SESSION['logged_user'];
?>
<head>

You cannot send headers (like session_start) after you already output content.