-5

可能重复:
PHP 中的“标头已发送”错误

我有一个托管在互联网上的网站。在此页面上,我需要一个会话才能开始。我得到错误

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

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

我的代码有什么问题?

<!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>
4

1 回答 1

4
<?php session_start(); ?>

需要在第一行的页面顶部:)

于 2012-05-10T23:33:05.873 回答