Contents of a variable is garbled when using sessions - please advice

From: Date: Wed, 02 Aug 2000 12:44:28 +0000
Subject: Contents of a variable is garbled when using sessions - please advice
Groups: php.general 
Request: Send a blank email to php-general+get-9676@lists.php.net to get a copy of this message
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" is attached to this mail. 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 (and yes, I do need the session)? Best regards, Jesper Juhl juhl@eisenstein.dk PS. I'm running PHP 4.0.0 on Slackware Linux 7.0, Apache 1.3.12 - this is a production system, and upgrading PHP is not currently an attractive option (but if that's the only thing that'll solve this, I guess I'll have to).

« previous php.general (#9676) next »