setcookie() has header problem -- no whitespace, text, or anything before the <?php tag
The following code has no whitespace or text before the opening php ta开发者_如何学Cg. When applied, I get a warning that says that the header has already been called "on line 3" (setcookie). I'm at a loss for why.
<?php
$value = 'something from somewhere';
setcookie("TestCookie", $value);
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
</head>
<body>
</body>
</html>
Thank you for any help.
If you have saved the file as UTF-8 with BOM (Byte Order Mark) three extra charcters are ouput at the start of the file.
These characters tell (dumb) applications that it is a UTF-8 file.
Using a BOM is not necessary for most applications.
http://en.wikipedia.org/wiki/Byte_order_mark
If you save the file again only without the BOM it should be fine.
Not sure if this is what's happening without seeing the actual file but it worth the shot.
Some editors show what kind of file it is. I use EditPlus as editor myself (Windows) and it shows the encoding of the file.
精彩评论