Page 1 of 1
Problem with using cookies: "Warning: Cannot modify header"
Posted: Fri Mar 27, 2009 8:00 am
by MicroBoy
It doesn't metter in which page I use cookies every time it says:
Code: Select all
Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\elektro\pjeset\index2.php:1) in C:\xampp\htdocs\elektro\pjeset\index2.php on line 2
This is my test page:
Code: Select all
<?php
setcookie("kodi", "kossss", time()+3600);
?>
<html>
<head>
<title>Test Page</title>
</head>
<body>
Test Text
</body>
</html>
Re: Problem with using cookies: "Warning: Cannot modify header"
Posted: Fri Mar 27, 2009 8:19 am
by Mark Baker
Is the script saved as UTF-8?
Re: Problem with using cookies: "Warning: Cannot modify header"
Posted: Fri Mar 27, 2009 12:51 pm
by MicroBoy
Mark Baker wrote:Is the script saved as UTF-8?
Thanks a lot

Everything it's ok, since I converted to UTF-8.

Re: Problem with using cookies: "Warning: Cannot modify header"
Posted: Fri Mar 27, 2009 12:53 pm
by Mark Baker
MicroBoy wrote:Mark Baker wrote:Is the script saved as UTF-8?
Thanks a lot

Everything it's ok, since I converted to UTF-8.

Major rule. Never save the actual script files as UTF-8. Learned that one myself the hard way
Re: Problem with using cookies: "Warning: Cannot modify header"
Posted: Fri Mar 27, 2009 1:29 pm
by JasonDFR
I save all of my scripts as UTF-8 and have never had a problem. Should I be worried? Under what conditions can there be problems?
EDIT: I do not write the unicode BOM however.
Re: Problem with using cookies: "Warning: Cannot modify header"
Posted: Mon Mar 30, 2009 2:49 am
by Mark Baker
JasonDFR wrote:I save all of my scripts as UTF-8 and have never had a problem. Should I be worried? Under what conditions can there be problems?
EDIT: I do not write the unicode BOM however.
I don't know if it's different for different platforms/web servers/editors.
Certainly with the editors that I use, if I save a file as UTF-8, then it automatically writes a BOM header to that file, which is totally transparent unless I view the file in a binary editor.
However, when the web server processes that file, it may see the BOM header as output and send it to the browser. Becaue it's the first thing in any file, then it gets sent before any headers in the script... and the web server sends its default headers, then the BOM marker as output.
I prefer not to take the risk, and have no need to do so because I don't embed anything that requires UTF-8 within the scripts themselves.
I've seen too much of other people having problems to want to fall into the same trap myself
Re: Problem with using cookies: "Warning: Cannot modify header"
Posted: Mon Mar 30, 2009 5:24 am
by php_east
Mark Baker wrote:JasonDFR wrote:I save all of my scripts as UTF-8 and have never had a problem. Should I be worried? Under what conditions can there be problems?
EDIT: I do not write the unicode BOM however.
I don't know if it's different for different platforms/web servers/editors.
Certainly with the editors that I use, if I save a file as UTF-8, then it automatically writes a BOM header to that file, which is totally transparent unless I view the file in a binary editor.
i have had to use utf-8 for some include files, the specifications calls for such. i think the utf-8 files are ok if they do not involve headers ( i.e. ok for include files and such ). it is ony when there is output to be done that the byte order marks come into play. i am not able to confirm this however, only my suspicion. i tend to use an editor which has on option setting for byte order mark use.