Page 1 of 1

session_start() - what are doing to my file!?!

Posted: Wed Jul 12, 2006 9:30 am
by hellolindsay
This is the weirdest error i've seen in a while...

I have this php file:

Code: Select all

<?
require "sound.mp3";
?>
So the php file echos the content of "sound.mp3". The php file is read by a java applet which loads the sound and plays it. It works fine.

Until i do this:

Code: Select all

<?
session_start();
require "sound.mp3";
?>
When the applet tries to read the php file now, it crashes. What the heck does 'session_start()' change that could possibly cause this?!?

Any ideas folks?

Lindsay

Posted: Wed Jul 12, 2006 6:04 pm
by Luke
wrong forum

Posted: Wed Jul 12, 2006 6:11 pm
by Burrito
it's ok in this forum:

I'd venture a guess that the session_start() is sending down a session cookie to the client and it's somehow confusing your java applet into thinking that the cookie is part of the sound.

that's pure speculation though. Have you tried moving the session_start() below the require() function?

Posted: Wed Jul 12, 2006 6:12 pm
by Weirdan
session_start send some headers (cookies and cache control) your applet might not understand. Besides that, using require to send out the file to client is, shall I say, questionable practice. Use readfile instead.

Posted: Wed Jul 12, 2006 6:13 pm
by Weirdan
Burrito wrote:it's ok in this forum:
It was in PHPDN originally

Posted: Wed Jul 12, 2006 6:13 pm
by Burrito
Weirdan wrote:It was in PHPDN originally
gotcha :wink:

Posted: Wed Jul 12, 2006 6:15 pm
by Weirdan
Have you tried moving the session_start() below the require() function?
That would lead to 'Headers already sent' error (thus the mp3 would be broken).

Posted: Wed Jul 12, 2006 6:36 pm
by Burrito
you're absolutely right.

Posted: Thu Jul 13, 2006 8:39 am
by hellolindsay
I want to be able to call the file path from a session variable, so i can't put session_start() after the require. And the "headers already sent" error would not occur if first ran ob_start(). None of these things help, though.

I agree that its probably sending extra headers to the client, but i don't want it too - all i want is to be able to *read* session variables, i don't need to change them. It shouldn't need to update the cookie.

Posted: Thu Jul 13, 2006 8:44 am
by Jenk
use readfile, as already suggested, and your woes will be resolved.

However.. because you are using a java-applet over HTTP you will need to allow for HTTP headers in your java applet.