2012-05-10 53 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(); ?> 

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

相關問題