Headers, session, include, - and header again?

Headers, session, include, - and header again?

am 04.12.2007 08:02:57 von jodleren

Hi all!

I have this problem, that I need to check the user (using session data
and some checks (included files)), then when ok, I can send a file to
the user.... meaning (simplified):

header("Pragma: no-cache");
header("Expires: -1");

session_start();
if($_SERVER['QUERY_STRING']=="logout")
session_unset();

include("session_control.php");
include('classes.php');

then, if needed, I might try this (sending a generated file to the
user):

header('Content-type: application/octet-stream');
header("Content-Disposition: attachment; filename=\"$filename\"");
readfile($userfile);

But, I cannot set the headers any more. Then again, I need the
$_SESSION information to check this first, and I need some included
functions to do that.

The very ugly solution is all code in one file. There must be another
way....

Any idea how to overcome this?

WBR
Sonnich

Re: Headers, session, include, - and header again?

am 04.12.2007 08:06:48 von luiheidsgoeroe

On Tue, 04 Dec 2007 08:02:57 +0100, jodleren wrote:

> Hi all!
>
> I have this problem, that I need to check the user (using session data=

> and some checks (included files)), then when ok, I can send a file to
> the user.... meaning (simplified):
>
> header("Pragma: no-cache");
> header("Expires: -1");
>
> session_start();
> if($_SERVER['QUERY_STRING']=="logout")
> session_unset();
>
> include("session_control.php");
> include('classes.php');
>
> then, if needed, I might try this (sending a generated file to the
> user):
>
> header('Content-type: application/octet-stream');
> header("Content-Disposition: attachment; filename=3D\"$filename\"");=

> readfile($userfile);
>
> But, I cannot set the headers any more. Then again, I need the
> $_SESSION information to check this first, and I need some included
> functions to do that.
>
> The very ugly solution is all code in one file. There must be another
> way....
>
> Any idea how to overcome this?

Includes are not the reason you can't send any headers anymore. They fac=
t =

that they produce output is. So, take care of that, strip all output fro=
m =

the included files that shouldn't be there (especially look for whitespa=
ce =

outside of php tags if the problem persists). Normally, PHP will inform =
=

you where the output started.
-- =

Rik Wasmus

Re: Headers, session, include, - and header again?

am 04.12.2007 08:51:38 von jodleren

On Dec 4, 9:06 am, "Rik Wasmus" wrote:
> On Tue, 04 Dec 2007 08:02:57 +0100, jodleren wrote:
> > Hi all!
>
> > I have this problem, that I need to check the user (using session data
....
> > Any idea how to overcome this?
>
> Includes are not the reason you can't send any headers anymore. They fact
> that they produce output is. So, take care of that, strip all output from
> the included files that shouldn't be there (especially look for whitespace
> outside of php tags if the problem persists). Normally, PHP will inform
> you where the output started.

Thanks, that was it.

WBR
Sonnich

Re: Headers, session, include, - and header again?

am 05.12.2007 16:47:51 von AnrDaemon

Greetings, jodleren.
In reply to Your message dated Tuesday, December 4, 2007, 10:02:57,

> I have this problem, that I need to check the user (using session data
> and some checks (included files)), then when ok, I can send a file to
> the user.... meaning (simplified):

> header("Pragma: no-cache");
> header("Expires: -1");

> session_start();
> if($_SERVER['QUERY_STRING']=="logout")
> session_unset();

> include("session_control.php");
> include('classes.php');

> then, if needed, I might try this (sending a generated file to the
> user):

> header('Content-type: application/octet-stream');
> header("Content-Disposition: attachment; filename=\"$filename\"");
> readfile($userfile);

> But, I cannot set the headers any more. Then again, I need the
> $_SESSION information to check this first, and I need some included
> functions to do that.

> The very ugly solution is all code in one file. There must be another
> way....

> Any idea how to overcome this?

One more idea - enable output buffering.


--
Sincerely Yours, AnrDaemon

Re: Headers, session, include, - and header again?

am 05.12.2007 17:01:25 von luiheidsgoeroe

On Wed, 05 Dec 2007 16:47:51 +0100, AnrDaemon =

wrote:

> Greetings, jodleren.
> In reply to Your message dated Tuesday, December 4, 2007, 10:02:57,
>
>> I have this problem, that I need to check the user (using session dat=
a
>> and some checks (included files)), then when ok, I can send a file to=

>> the user.... meaning (simplified):
>
>> header("Pragma: no-cache");
>> header("Expires: -1");
>
>> session_start();
>> if($_SERVER['QUERY_STRING']=="logout")
>> session_unset();
>
>> include("session_control.php");
>> include('classes.php');
>
>> then, if needed, I might try this (sending a generated file to the
>> user):
>
>> header('Content-type: application/octet-stream');
>> header("Content-Disposition: attachment; filename=3D\"$filename\"")=
;
>> readfile($userfile);
>
>> But, I cannot set the headers any more. Then again, I need the
>> $_SESSION information to check this first, and I need some included
>> functions to do that.
>
>> The very ugly solution is all code in one file. There must be another=

>> way....
>
>> Any idea how to overcome this?
>
> One more idea - enable output buffering.

Which is, 99% of the time it's used to be able to send headers, just =

obscuring a fault in the design of the script. It works, it's just not =

good practise.
-- =

Rik Wasmus

Re: Headers, session, include, - and header again?

am 05.12.2007 18:24:12 von AnrDaemon

Greetings, Rik Wasmus.
In reply to Your message dated Wednesday, December 5, 2007, 19:01:25,

> Which is, 99% of the time it's used to be able to send headers, just
> obscuring a fault in the design of the script. It works, it's just not
> good practise.

Using page compression You're forced to use buffering anyway.
So not a big deal (But youre in fact right)


--
Sincerely Yours, AnrDaemon