473,800 Members | 2,418 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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("sessio n_control.php") ;
include('classe s.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=\"$fil ename\"");
readfile($userf ile);

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 1767
On Tue, 04 Dec 2007 08:02:57 +0100, jodleren <so*****@hot.ee 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("sessio n_control.php") ;
include('classe s.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=\"$fil ename\"");
readfile($userf ile);

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.comwro te:
On Tue, 04 Dec 2007 08:02:57 +0100, jodleren <sonn...@hot.ee 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
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("sessio n_control.php") ;
include('classe s.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=\"$fil ename\"");
readfile($userf ile);
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*******@free mail.ru>

Dec 5 '07 #4
On Wed, 05 Dec 2007 16:47:51 +0100, AnrDaemon <an*******@free mail.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("sessio n_control.php") ;
include('classe s.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=\"$fil ename\"");
readfile($userf ile);
>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*******@free mail.ru>

Dec 5 '07 #6

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

Similar topics

1
2451
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 http://www.macromedia.com/devnet/mx/dreamweaver/articles/php_cart.html. When I try to start a session or create a cookie, I get the following errors. Warning: Cannot send session cache limiter - headers already sent (output started at /wrapper_head2.php:27) in /cart.php on line 13 Warning: Cannot...
6
4327
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 serves two purposes, 1. it contains a tab strip with response.redirects to navigate to the other pages; 2. I authenticate the user by check to see if a cookie exists, if it doesn't I redirect to a login screen.
3
53663
by: lawrence k | last post by:
I'm getting this warning: PHP Warning: session_start(): Cannot send session cache limiter - headers already sent in /home/httpd/vhosts/monkeyclaus.org/httpdocs/media/audio/pdsIncludes/CommandStartSession.php on line 14 line 14 is this:
1
2591
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 page. -----Start error message ----------- Response object error 'ASP 0156 : 80004005' Header Error
4
5951
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, however and am really struggling with managing sessions in PHP, based on my experiences with managing sessions in ASP. 99.9% of the feedback I have seen when dealing with the errors has referred to having whitespace before the <?php or after the...
2
4341
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 displayed next. Immediately at this point, it logs out the user. It is logging out the user because after checking $_SESSION == '1' - it finds that its not 1, and therefore displays login section again and a related message. The website is being...
4
1842
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 D:\virtualservers\182763\root\test\login\checklogin.php:1) in D:\virtualservers\182763\root\test\login\checklogin.php on line 18 Warning: session_register() : Cannot send session cache limiter - headers already sent (output started at...
2
1337
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 session_destroy() line saying it started output. But it's not being called! I removed the header() line below session_destroy() but it still gives the same error so it seems to be session_destroy() existing in the
6
11501
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
9551
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10505
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10253
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10033
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6811
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5606
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4149
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3764
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2945
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.