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

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
hellolindsay
Forum Newbie
Posts: 6
Joined: Wed Jul 12, 2006 9:23 am

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

Post 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
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

wrong forum
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post 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?
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post 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.
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

Burrito wrote:it's ok in this forum:
It was in PHPDN originally
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

Weirdan wrote:It was in PHPDN originally
gotcha :wink:
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post 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).
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

you're absolutely right.
hellolindsay
Forum Newbie
Posts: 6
Joined: Wed Jul 12, 2006 9:23 am

Post 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.
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Post 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.
Post Reply