UTF-8 and session problem.

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
User avatar
dethron
Forum Contributor
Posts: 370
Joined: Sat Apr 27, 2002 11:39 am
Location: Istanbul

UTF-8 and session problem.

Post by dethron »

Hi guys;

I'm sure that there are many who were faced the problem that i m gonna specify.

I'm using Dreamweaver as my PHP editor. Until now, I haven't use the UTF-8 encoding. But now I'm working on a project that is in my native language. And since I want to display some special characters I changed the encoding type of some of my files from win-1254 to utf-8.

But then i got the following error :
Warning: Cannot send session cache limiter - headers already sent (output started at c:\apache\htdocs\adven\cadmin\cadmin_main.php:1) in session.php on line 2

When i open the file in Homesite, or phpEdit I just find a special hidden character at the beginning of the file, the character is .

I have no information about these set of chars but when i deleted these and save the file, the "headers sent" error was gone. However the characters like "çşğöı" are gone, too.

I think this is very interesting and caused me more than 6 hours. Do you know anything about what happened to me? Any help would be great.

Good Luck..
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

User avatar
dethron
Forum Contributor
Posts: 370
Joined: Sat Apr 27, 2002 11:39 am
Location: Istanbul

Post by dethron »

feyd probably you did not understand my problem.
here is the session.php

Code: Select all

<?php
	session_start();
?>
How can i send anything on line 1 :)
The character is hidden, it doesn't shown using Dreamweaver.
I edit the file using vi after I upload it to server.
vi displays the hidden characters.
The problem is not about session.
It stems from some hidden characters.
When I delete these hidden chars, then any browser is unable to select UTF-8 encoding even if I placed following line in my HTML.

<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

your code should be prior to all text output, including these special characters.
User avatar
dethron
Forum Contributor
Posts: 370
Joined: Sat Apr 27, 2002 11:39 am
Location: Istanbul

Post by dethron »

But the characters are not shown....
The editor puts them when i select UTF-8.

since I get this error, after hours of digging I found them. In windows they are not shown.
however when you edit the file via "vi" in linux, you are able to see them.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

how about seperating your code from your html?
User avatar
dethron
Forum Contributor
Posts: 370
Joined: Sat Apr 27, 2002 11:39 am
Location: Istanbul

Post by dethron »

The code is already seperated,
do you want to see the file?
I can send it via email to you, and explain the problem in more detailed.
Thnx.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

You can post it here.. could be useful to someone else..
User avatar
dethron
Forum Contributor
Posts: 370
Joined: Sat Apr 27, 2002 11:39 am
Location: Istanbul

Post by dethron »

i'm sure you didn't understand the problem. :(
the "" are the hidden characters.
they are invisible if your using dreamweaver.
i saw them when i tried to edit the file in my linux server. :)
Any windows editor except homesite are not able to display this chars.
I thing they are some kind of flags that tells the operating system, the file is UTF-8 encoded.
thnx.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

how does removing the characters, and calling [php_man]header[/php_man]('Content-type: text/html; charset=UTF-8') at the beginning of the file go? (you may need to fiddle with the string a bit)
User avatar
dethron
Forum Contributor
Posts: 370
Joined: Sat Apr 27, 2002 11:39 am
Location: Istanbul

Post by dethron »

i did this before, and surprisingly some characters are changed.
by the way, if I upload this file to another server, server displayed characters(şöçğ) very well.
i know it is strange but this is the way it is :(

one of friends told me he had same problem once, and he thinks
converting win1252 file to utf8 in dreamweaver causes this problem.

now, when your last suggestion is applied the situation is that,
since the chars are removed the session error is solved,
however, any browser(I tried 5 of them) tries to set the encoding to the default encoding (although the file has
header('Content-type: text/html; charset=UTF-8') ; line.).

thnx.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

you may need to set the DTD too.. Here's specific info on the character set UTF-8

Code: Select all

Name: UTF-8                                                    &#1111;RFC3629]
MIBenum: 106
Source: RFC 3629
Alias: None
User avatar
dethron
Forum Contributor
Posts: 370
Joined: Sat Apr 27, 2002 11:39 am
Location: Istanbul

Post by dethron »

Hmmm, i do not know about these things, can you explain?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

ignore the DTD idea.. I did some further checking.. it doesn't appear to have character encoding controls
Post Reply