[Help] Annoying problem relating session functions!

Problems with the Windows version of XAMPP, questions, comments, and anything related.

[Help] Annoying problem relating session functions!

Postby lucky_clover » 16. February 2007 03:32

This is quite weird problem relating session function of PHP. I think it may be because of settings in php.ini. I'm using xampp 1.5.5 and I don't modify any settings in php.ini, just fresh installation.

I have 2 files as follows:

index_en.php
Code: Select all
<?php
session_start();
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Title in English</title>
</head>
<body>
<?php
   echo "Session ID: " . session_id();
?>
</body>
</html>


index_vn.php
Code: Select all
<?php
session_start();
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Tiêu đề bằng tiếng Việt</title>
</head>
<body>
<?php
   echo "ID của session: " . session_id();
?>
</body>
</html>


I wrote both files using notepad. The first I saved as ASCII encoding text file, the second saved as UTF-8 encoding text file. When loaded in browser, the index_en.php is fine, but the index_vn.php gave these warning:
Code: Select all
Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at C:\xampp\htdocs\test\index_vn.php:1) in C:\xampp\htdocs\test\index_vn.php on line 2

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at C:\xampp\htdocs\test\index_vn.php:1) in C:\xampp\htdocs\test\index_vn.php on line 2


Also, the index_vn.php created different session ids every time I reload the page, that's odd.

I uploaded these two to a host and they run correctly. You can see these pages here:
http://troyvn.byethost31.com/temp/index_en.php
http://troyvn.byethost31.com/temp/index_vn.php

I think this problem may be caused by settings in php.ini, but I don't know how to correct it. Anyone has any idea?
lucky_clover
 
Posts: 2
Joined: 16. February 2007 03:12

Postby Wiedmann » 16. February 2007 09:32

the second saved as UTF-8 encoding text file
Code: Select all
<?php
session_start();
?>

Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at C:\xampp\htdocs\test\index_vn.php:1)

There is an utf-8 bom at the beginning of your file. (reconfigure your editor to: don't write a bom with utf-8 files).
Wiedmann
AF Moderator
 
Posts: 17102
Joined: 01. February 2004 12:38
Location: Stuttgart / Germany

Postby lucky_clover » 16. February 2007 11:11

Wiedmann wrote:There is an utf-8 bom at the beginning of your file. (reconfigure your editor to: don't write a bom with utf-8 files).


Thanks a lot! I use UltraEdit and configure it to not write UTF-8 bom, and the problem's gone! But I still wonder why this problem doesn't occur when I uploaded them to my host! Does Linux treat UTF-8 text files differently from Windows?
lucky_clover
 
Posts: 2
Joined: 16. February 2007 03:12

Postby Wiedmann » 16. February 2007 11:58

Does Linux treat UTF-8 text files differently from Windows?

No.

But I still wonder why this problem doesn't occur when I uploaded them to my host!

a) you transfer the files in text mode and the ftp client removes the bom (convert dos to unix line endings) (btw, I don't know if a client really remove the bom in this case)

b) or output buffering is enabled at your unix host.
Wiedmann
AF Moderator
 
Posts: 17102
Joined: 01. February 2004 12:38
Location: Stuttgart / Germany


Return to XAMPP for Windows

Who is online

Users browsing this forum: No registered users and 237 guests