Page 1 of 1

session_start() and UTF-8 characters error

Posted: Mon Jun 16, 2003 1:39 pm
by dennisbrowne
Situation: I am trying to display Japanese characters in my PHP site. I set up a test case where I first do a session_start(), then echo out some Japanese characters. I save the file as UTF-8.

The code looks like:
<?php
session_start();
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<?php
echo "Home:ホーム<br>";
?>
</body>
</html>


When bringing up this page I get the error:

Warning: Cannot send session cookie - headers already sent by (output started at /var/www/html/fbx_SettingsUTF8.php:5) in /var/www/html/fbx_SettingsUTF8.php on line 6

Warning: Cannot send session cache limiter - headers already sent (output started at /var/www/html/fbx_SettingsUTF8.php:5) in /var/www/html/fbx_SettingsUTF8.php on line 6


When I save the file as ANSI I do not get the error, but then the Japanese characters do not display correctly.

Does anybody know a resolution for this? The session_start() is causing the problem?

Thanks
Dennis
dennis_e_browne aatt hotmail ddott com

Posted: Mon Jun 16, 2003 3:04 pm
by cactus
This issue is similar to:

viewtopic.php?t=1157

Ensure you are not outputting any thing including whitespace before session_start();, usually outside your <?php ?> declaration.

Regards,

Posted: Mon Jun 16, 2003 3:39 pm
by dennisbrowne
It has somethiong to do with me saving the file as UTF-8. There are no blank lines before the <?php so the mentioned post does not quite match this scenario. Anyone else know?

Posted: Tue Jun 17, 2003 3:00 am
by twigletmac
Is that the full file? The error message says that output has been sent on line 5 (and that it tried to send the cookie on line 6) but in the code above session_start() is on line 2 not line 6 :?

Mac

Posted: Tue Jun 17, 2003 4:20 am
by boban
There are no blank lines before the <?php but there is the BOM mark.

http://www.unicode.org/unicode/faq/utf_bom.html#22

Microsoft tools, most prominently Windows Notepad, prefix the BOM to Unicode text files regularly. Upon saving a Unicode text file in Notepad, the BOM is always prefixed.

<?php

You should remove them.
UltraEdit-32 is able to display the BOM.