【发布时间】:2010-05-05 00:04:20
【问题描述】:
我使用了在网上找到的示例并将其应用于我的代码:
<?php
session_start();
if (isset($_REQUEST["email"]))
{
$_SESSION["name"] = true;
$host = $_SERVER["HTTP_HOST"];
$path = dirname($_SERVER["PHP_SELF"]);
$sid = session_name() . "=" . session_id();
header("Location: index.php?$sid");
exit;
}
?>
<!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>
...
...
and rest of the html code
当我打开这个页面时,我得到一个错误:
Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /data/server/user/directory/sub-directory/login.php:1) in /data/server/user/directory/sub-directory/login.php on line 2
Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /data/server/user/directory/sub-directory/login.php:1) in /data/server/user/directory/sub-directory/login.php on line 2
我环顾四周以解决这个问题,并且在这个网站上也看到了一些关于这个的帖子,但我就是无法很好地掌握这个......找不到答案。
请帮忙。
谢谢。
【问题讨论】:
-
这应该是 SO 上被问到最多的问题
-
你刚刚让我拍了两遍。
-
您在互联网上找到的粘贴代码就像您在街上发现的口香糖。 :)
-
首先,我已经说过我在这个网站上寻找过这种错误,但找不到答案……不知道 BOM 是什么意思。这就是我发帖的原因,希望有人能指引我走向正确的方向……而 Grossvogel 和 ZZ coder 做到了。你的 cmets 关于这篇文章是重复的或者告诉我关于口香糖的事情不会有帮助。在某一时刻,你们所有人都做了同样的事情......复制/粘贴并学习了自己的方式。我现在正处于那个阶段。很抱歉,无论出于何种原因,这让你们中的一些人感到困扰。并感谢那些非常乐于助人的人。