Cannot Add Header Information Error 
Author Message
 Cannot Add Header Information Error

I'm using PHP sessions to store the session data in a database, and thus am
using the session_set_save_handler function to set up custom handlers.  I
also set session_cache_limiter('none').  However, upon logging out by
calling session_destroy(), I am trying to redirect the output back to the
login screen with header("Location: index.php").  However, I receive the
following error:

Warning: Cannot add header information - headers already sent by (output
started at /home/vansvaul/public_html/outreach/sess.php:156)


call, but that just suppresses the error message, and the redirect still
does not complete.  I've tried to use a flush() before the header() call
also, to no avail.

So, how can I make this redirect work?  The headers are being sent by the
sess.php file, which includes all of the functions for
session_set_save_handler and so forth.

Thanks for any help.

Regards,
Van



Thu, 14 Apr 2005 03:01:41 GMT  
 Cannot Add Header Information Error

Quote:
> I'm using PHP sessions to store the session data in a database, and thus
am
> using the session_set_save_handler function to set up custom handlers.  I
> also set session_cache_limiter('none').  However, upon logging out by
> calling session_destroy(), I am trying to redirect the output back to the
> login screen with header("Location: index.php").  However, I receive the
> following error:

> Warning: Cannot add header information - headers already sent by (output
> started at /home/vansvaul/public_html/outreach/sess.php:156)


> call, but that just suppresses the error message, and the redirect still
> does not complete.  I've tried to use a flush() before the header() call
> also, to no avail.

> So, how can I make this redirect work?  The headers are being sent by the
> sess.php file, which includes all of the functions for
> session_set_save_handler and so forth.

Is there a FAQ somewhere that we could add information about 'Cannot add
header information'-related information to?  If not, should someone write
one? (Am volunteering, if so)

To answer the question, your script is producing output somewhere before
sess.php:156.  Once output has been sent to the client, you can't add any
more headers (cookie(), header() calls, primarily).  Either move whatever
bit of code is generating headers, or use output buffering (look up
ob_start() et al) to prevent output from being sent until you intentionally
flush the buffer.



Fri, 15 Apr 2005 02:55:12 GMT  
 Cannot Add Header Information Error

Quote:
> Is there a FAQ somewhere that we could add information about 'Cannot add
> header information'-related information to?  If not, should someone write
> one? (Am volunteering, if so)

Owen, this is a new group (still) and AFAIK there is no current FAQ specific
to this group.

Someone was sending periodic group stats, but I'd wouldn't mind seeing
weekly FAQ messages (similar to comp.lang.perl.misc)

It may be in the best interest of the group to start a top-level thread
requesting collaboration on the creation of an FAQ site, and potentially a
weekly FAQ reminder post.  I would help wherever I could.

This may help stem the flow of 'why does my script break when I use $foo to
access my form variables'.

regards,
reggie.



Fri, 15 Apr 2005 03:21:46 GMT  
 Cannot Add Header Information Error


[snip]

Quote:
> Warning: Cannot add header information - headers already sent by
(output
> started at /home/vansvaul/public_html/outreach/sess.php:156)

Have a look at the file sess.php. Go to line 156, and see what could
possibly be outputting *anything* to the client both _on_ and _around_
this line. It could be a blank line that is not contained in php code,
e.g.
##########################
<?php

blah blah blah;
?>

<?php
blah
......
##########################

or it could be a rogue echo, print, sprintf, etc. If you can't find
the problem, post the source code

Quote:

function
> call, but that just suppresses the error message, and the redirect
still
> does not complete.  I've tried to use a flush() before the header()
call
> also, to no avail.

Flush() is the wrong command to be using here. Flush() will just send
anything waiting in the output buffers on it's way to the client.

You could always buffer your output with ob_start() -- then the
problem is gone (most likely). But finding the cause & fixing it is
better than putting in workarounds.

Cheers,
Will M
--
Registered Linux User #273744
<www.volutin.net -- everything irrelevant>



Fri, 15 Apr 2005 19:31:18 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. ERROR: Cannot modify header information headers already sent by (output started at

2. Cannot add header information

3. Cannot modify header information

4. configure error: cannot find a cracklib header file

5. cannot use parameters from subroutine-header when calling Lahey Fortran 90 DLL from Delphi 3

6. TIFF Header Information

7. Excel - File Header Information

8. Information about elf header

9. SB cannot add new method

10. Cannot add a new record under Win95B (CAVO 1.0c)

11. How to add a header to a file?

12. Cannot add Labview Runtime to Installer.

 

 
Powered by phpBB® Forum Software