开发者

I'm getting these errors returned from my free host, i'm not sure how to tell where my headers are?

开发者 https://www.devze.com 2023-01-27 06:00 出处:网络
I\'m getting errors like t开发者_StackOverflowhis Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /www/zymichost.com/m/i/t/mi

I'm getting errors like t开发者_StackOverflowhis Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /www/zymichost.com/m/i/t/mitchell931993/htdocs/connected/index.php:5) in /www/zymichost.com/m/i/t/mitchell931993/htdocs/connected/index.php on line 5

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /www/zymichost.com/m/i/t/mitchell931993/htdocs/connected/index.php:5) in /www/zymichost.com/m/i/t/mitchell931993/htdocs/connected/index.php on line 5

I'm not sure how to fix them. My website is an attempted social networking site, its in the test phases atm. Can you tell em what wrong with my code?

Header.php

<?php 
if(isset($_SESSION['login'])){
$szUser=$_SESSION['login'];
echo "<table width=\"980\" border=\"0\" align=\"center\">
<tr>
<td width=\"490\" align=\"left\">Connected - Welcome $szUser</td>
<td width=\"490\" align=\"right\"><a href=\"home.php\">Log Out</a></td>
</tr>
</table><hr width=980 align=\"center\">";
}
elseif(!isset($_SESSION['login'])){
echo "<table width=\"\" border=\"0\" align=\"center\">
<tr>
<td width=\"490\" align=\"left\"> Connected - You are not logged in...</td>
<td width=\"490\" align=\"right\"><a href=\"login.php\">Please login here</a></td>
</tr>
</table><hr width=980 align=\"center\">";
}
?>

And this is the index page that uses it

<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<?php session_start();?>
<title>Connected - Home</title>
</head>
<body>
<div align=center>
<?php
include_once "resources/header.php";
echo "<table><tr><td width=980 height=500 align=center valign=middle>";
include_once "resources/login.html";
echo "</td></tr></table>";
?>
</div>
</body>
</html>


<?php session_start();?> Needs to go to the very top of your page. Like so:

<?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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

If you put it way down your headers are already sent (the HTML text starting with <!Doctype...).

A good write-up on this error you can find here: Headers already sent. Which makes these two basic points on why the error might have occured:

  • Whitespace before the opening php tag
  • Outputting something to the browser before you use session_start, header, setcookie etc
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号