2012-05-10 39 views
-5

Possible Duplicate:
“Header Already Sent” error in PHP收到此错误:警告:在session_start()[function.session启动]:

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

警告:session_start()[function.session-start] 15)在/home/content/58/9335458/html/ourgames.php在线7

警告:session_start()[function.session-start]:无法发送会话缓存限制器 - 头已发送(输出开始于/home/content/58/9335458/html/ourgames.php:15)in /home/content/58/9335458/html/ourgames.php on line 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> 
+5

**看看这个页面的右侧部分对于类似问题,** – zerkms

+2

我甚至不能指顶特别重复,因为有*十亿个*类似的问题 – zerkms

回答

4
<?php session_start(); ?> 

需求是在页面的第一行:)

相关问题