session_start() and UTF-8 characters error

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
dennisbrowne
Forum Newbie
Posts: 2
Joined: Mon Jun 16, 2003 1:39 pm

session_start() and UTF-8 characters error

Post 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
User avatar
cactus
Forum Regular
Posts: 343
Joined: Tue Jun 10, 2003 4:16 am
Location: UK

Post 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,
dennisbrowne
Forum Newbie
Posts: 2
Joined: Mon Jun 16, 2003 1:39 pm

Post 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?
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post 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
boban
Forum Newbie
Posts: 1
Joined: Tue Jun 17, 2003 4:20 am

Post 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.
Post Reply