开发者

php session_start() error

i've used a sample found on online and applied it to my code:

<?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 "-/开发者_如何学C/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

When I open this page, I got an error:

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

I looked around to resolve this issue and saw few posts about this in this site also, but I just can't get a good grip on this...can't find the answer.

Please help.

Thanks.


NotePad is known to insert BOM in the beginning of the text file. When you save the file, please make sure you don't select Unicode or UTF-8 as encoding.

You can confirm if BOM is inserted by making a hex dump of the file. You can use this utility to do it,

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

If it doesn't start with 0x3C, you got BOM.


Check for a space, newline, or any other characters before the <?php, Any output before session_start() will cause that error.

The error specifically states that the output is on line 1 of login.php, while session_start() is on line 2. Thus it's probably a space or some other character.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜