473,397 Members | 1,972 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

Headers, session, include, - and header again?

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
Dec 4 '07 #1
5 1749
On Tue, 04 Dec 2007 08:02:57 +0100, jodleren <so*****@hot.eewrote:
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?
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.
--
Rik Wasmus
Dec 4 '07 #2
On Dec 4, 9:06 am, "Rik Wasmus" <luiheidsgoe...@hotmail.comwrote:
On Tue, 04 Dec 2007 08:02:57 +0100, jodleren <sonn...@hot.eewrote:
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
Dec 4 '07 #3
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 <an*******@freemail.ru>

Dec 5 '07 #4
On Wed, 05 Dec 2007 16:47:51 +0100, AnrDaemon <an*******@freemail.ru
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 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.
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
Dec 5 '07 #5
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 <an*******@freemail.ru>

Dec 5 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: None | last post by:
Hello, I am a total newbie to PHP and programming in general. I am playing around with a PHP / MySQL shopping cart script which I found at...
6
by: Sam | last post by:
I have some issues with HTTP Headers and I was hoping for some pointers or references to good articles. Here is the problem. I have 6 .aspx pages, each page contains a common .ascx. This ascx...
3
by: lawrence k | last post by:
I'm getting this warning: PHP Warning: session_start(): Cannot send session cache limiter - headers already sent in...
1
by: kgcsinte | last post by:
I hope someone can help with this one. This is a include file that is used to check if a user is logged in before displaying a page. I get this error when any page that references the include...
4
by: three-eight-hotel | last post by:
I'm somewhat of a newbie to PHP coding, but have developed a site using the technology, and have been pleasantly surprised by the capabilities offered. I am more comfortable in the ASP world,...
2
by: jwhite68 | last post by:
The essence of my problem is this. 1. I login to my website with user/password. 2. I select any option, which effectively re-calls index2.php with some additional parameters, to control whats...
4
by: craigtomo | last post by:
I am getting the following error when i try to log on to my data base Warning: session_register() : Cannot send session cookie - headers already sent by (output started at...
2
by: mercedes1954 | last post by:
Hi, I am using header("Location: in two places in my script, but they are in mutually exclusive blocks i.e if one runs, the other can't. However, an error is thrown pointing to the...
6
Markus
by: Markus | last post by:
Things to discuss: Headers What are they? What does PHP have to do with headers? Why can they only be sent before any output? Common causes
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.