收到此错误:警告:session_start()[function.session-start]:

时间:2012-05-10 23:30:34

标签: php mysql session header

  

可能重复:
  “Header Already Sent” error in PHP

我在互联网上托管了一个网站。在这个页面上,我需要一个会话开始。 我收到了错误

警告:session_start()[function.session-start]:无法发送会话cookie - 已经发送的标头(/home/content/58/9335458/html/ourgames.php:15中的输出)/ home /第7行的内容/ 58/9335458 / html / ourgames.php

警告:session_start()[function.session-start]:无法发送会话缓存限制器 - 已在/ home /中发送的标头(在/home/content/58/9335458/html/ourgames.php:15开始输出)第7行的内容/ 58/9335458 / html / ourgames.php

我的代码出了什么问题?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"         "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<?php
session_start ();
?>

<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>site</title>
<meta name="description" content="Web Application" />
<meta name="keywords" content="web, application" />
<link href="css/main.css" rel="stylesheet" type="text/css" />
</head>
<body>



<div id="header">
<div id="phapsy">
    <h1><a href="index.html">site</a></h1>
    </div>

<div id="menuholder">
    <ul id="menu">
        <li><a href="index.html">home</a></li>
        <li class="active"><a href="ourgames.php">our games</a></li>
        <li><a href="register.php">register</a></li>
        <li><a href="aboutus.php">about us</a></li>
        <li><a href="contact.html">contact us</a></li>
    </ul>
    </div>


    <?php

if (isset($_SESSION['username']));
else
echo"        <div id='login'>  
<form action='login.php' method='POST'>
<table>
<tr><td>Username: </td><td><input type='text' name='username'/></td><td>Password: </td>    <td><input type='password' name='password'/></td> <td><input type='submit' name='submit'     value='Login'/></td></tr>
</table>
</form>
</div>";

?>



</div>

<div id="teaser">
    <div class="wrap">
        <div id="image"></div>
        <div class="box">

<?php

if (isset($_SESSION['username']))
echo "<h2>Welcome to the page about the app!</h2>
<p>Information about the application will go here</p>";
else
    echo("<h2>You must be logged in to view this page. <br>
<a href='register.php'>Register</a> to gain access and learn more about <br>the     application.</h2>

");
?>




        </div>

    </div>
</div>

<div id="bar">
    <div class="wrap">

    </div>
</div>


<?php

if (isset($_SESSION['username']))
echo "
<div class='wrap'>
    <div class='col'>
        <h3>Data</h3>

        <p>More info </p>

    </div>
    <div class='col'>
        <h3>Value</h3>

        <p>More info</p>

    </div>
    <div class='col last'>
    <h3>Goal</h3>

        <p>More info</p>

    </div>
</div>

<div id='footer'>

</div>
";
else
echo("
<div id='footer'>

</div>  



");
?>

</body>
</html>

1 个答案:

答案 0 :(得分:4)

<?php session_start(); ?>

需要位于FIRST行的页面顶部:)