PHP 4.0 Bug #5922: Output garbled when using sessions
| From: | juhl at eisenstein dot dk | Date: | Wed, 02 Aug 2000 13:09:47 +0000 |
| Subject: | PHP 4.0 Bug #5922: Output garbled when using sessions | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-27440@lists.php.net to get a copy of this message | ||
From: juhl@eisenstein.dk
Operating system: Slackware Linux 7.0
PHP version: 4.0.0
PHP Bug Type: Session related
Bug description: Output garbled when using sessions
Hi,
I have a very wierd problem with sessions (I suspect trans-sid is
involved).
I try to open a file and read its contents into a variable to do som
string magic on it before passing it to the client, but whenever I output
the contents of the variable it turns up completely garbled in the
browser.
The funny thing is that if I save the contents of the variable to a file
instead of sending it to the client, then the saved file is OK.
This only happens when I'm using sessions (both the build in ones and my
own session handling functions), if I don't call session_start() then
output is fine.
How the file is garbled is very different from one file to another, and
if I just change a few lines, then completely new areas are messed up.
Below is a small program that shows the bug, and a dump of one file that
is messed up by this procedure - that should make it possible for you to
reproduce.
I have the following code:
<?php
session_start();
$filename = "test.txt";
$f = fopen($filename, "r");
$contents = fread($f, filesize($filename));
echo $contents;
?>
The file "test.txt" contains the following:
<table border="0" cellpadding="0" cellspacing="0"
width="111px" height="141px">
<tr>
<td width="29" height="20"><img
src="../images/menu_01.gif"></td>
<td colspan="2" background="../images/menu_02.gif" width="82"
height="20" valign="bottom"><a
href="#">Login</a></td>
</tr>
<tr>
<td width="29" height="16"><img
src="../images/menu_03.gif"></td>
<td colspan="2" background="../images/menu_04.gif" width="82"
height="16" valign="bottom"><a
href="#">Logout</a></td>
</tr>
<tr>
<td width="29" height="16"><img
src="../images/menu_05.gif"></td>
<td colspan="2" background="../images/menu_06.gif" width="82"
height="16" valign="bottom"><a href="#">PR
</a></td>
</tr>
<tr>
<td width="29" height="16"><img
src="../images/menu_07.gif">
</td>
<td colspan="2" background="../images/menu_08.gif" width="82"
height="16" valign="bottom"><a
href="#">B</a></td>
</tr>
<tr>
<td width="29" height="16"><img
src="../images/menu_09.gif"></td>
<td colspan="2" background="../images/menu_10.gif" width="82"
height="16" valign="bottom"><a
href="#">P</a></td>
</tr>
<tr>
<td width="29" height="16"><img
src="../images/menu_11.gif"></td>
<td colspan="2" background="../images/menu_12.gif"
width="82" height="16" valign="bottom"><a
href="#">Spørg</a></td>
</tr>
<tr>
<td width="29" height="16"><img
src="../images/menu_13.gif"></td>
<td colspan="2" background="../images/menu_14.gif"
width="82" height="16" valign="bottom"><a
href="#"> </a></td>
</tr>
<tr>
<td width="29" height="25"><img
src="../images/menu_15.gif" width="29" height="25"></td>
<td width="61" height="25"><img
src="../images/menu_16.gif" width="61" height="25"></td>
<td width="21" height="25"><img
src="../images/menu_17.gif" width="21" height="25"
usemap="#lukMenu" border="0"
alt="Luk"></td>
</tr>
</table>
When running the code as above I get the following in Lynx:
[menu_01.gif] Login
[menu_03.gif] Logout
[menu_05.gif] PR
[menu_07.gif] Login
[menu_03.gif] Logout
[menu_05.gif] PR
[menu_07.gif] B
[menu_09.gif] tñÿ¿Ðh@ñÿ¿¤ o@Üñÿ¿DB(¨ñÿ¿h@ñÿ¿¤ o@àñ"#">Logout
[menu_05.gif] PR
[menu_07.gif] B
[menu_09.gif] P
[menu_11.gif] PR
[menu_07.gif] B
[menu_09.gif] P
[menu_11.gif] Spørg
[menu_13.gif] B
[menu_09.gif] P
[menu_11.gif] Spørg
[menu_13.gif]
[menu_15.gif] P
[menu_11.gif] Spørg
[menu_13.gif]
[menu_15.gif] [menu_16.gif] [menu_17.gif] Spørg
[menu_13.gif]
[menu_15.gif] [menu_16.gif] Luk
?PHPSESSID=62d8913fdddd20770795f37e35c10d4e"#">
[menu_15.gif] [menu_16.gif] Luk
The correct output (as will be given if I remove session_start() ) is :
[menu_01.gif] Login
[menu_03.gif] Logout
[menu_05.gif] PR
[menu_07.gif] B
[menu_09.gif] P
[menu_11.gif] Spørg
[menu_13.gif]
[menu_15.gif] [menu_16.gif] Luk
Could someone please tell me what's wrong here?
Best regards,
Jesper Juhl
juhl@eisenstein.dk
PS. I'm running PHP 4.0.0 on Slackware Linux 7.0, Apache 1.3.12