php session_start()错误

时间:2010-05-05 00:04:21

标签: php mysql

我使用了在线找到的样本并将其应用到我的代码中:

<?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

我环顾四周解决了这个问题,并且在这个网站上也看到了很少关于这个的帖子,但是我无法抓住这个...找不到答案。

请帮忙。

感谢。

2 个答案:

答案 0 :(得分:0)

<?php之前检查空格,换行符或任何其他字符,在session_start()之前的任何输出都会导致该错误。

错误明确指出输出位于login.php的第1行,而session_start()位于第2行。因此,它可能是空格或其他字符。

答案 1 :(得分:0)

已知NotePad会在文本文件的开头插入BOM。保存文件时,请确保不要选择Unicode或UTF-8作为编码。

您可以通过对文件进行十六进制转储来确认是否插入了BOM。您可以使用此实用程序来执行此操作,

http://www.richpasco.org/utilities/hexdump.html

如果它不是以0x3C开头,那么就是BOM。

相关问题