Headers not sent

I’m using a PHP include to pull in a wiki script into a .php page.

It does appear to pull the page in, but without any styling or formatting, and with the warnings:

"Warning: Cannot modify header information - headers already sent by (output started at /Volumes/Formac_120Gb_Webserver/HUCKLOW.COM/test/newsite/wiki.php:6) in /Volumes/Formac_120Gb_Webserver/HUCKLOW.COM/test/newsite/doku/inc/auth.php on line 313

Warning: Cannot modify header information - headers already sent by (output started at /Volumes/Formac_120Gb_Webserver/HUCKLOW.COM/test/newsite/wiki.php:6) in /Volumes/Formac_120Gb_Webserver/HUCKLOW.COM/test/newsite/doku/inc/actions.php on line 163"

I must admit I don’t understand header information! What does it all mean?

Hugh


dynamo mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Headers are sent by the server to the browser whenever any content is
streamed back to the browser. Headers identify the content that will
follow, tell it the format, size, cache status, etc. and serve as
machine-friendly metadata, much like the cover of a book tells you
what you will find inside.

This particular error probably means that the script wants to redirect
the user to another page, but cannot, because that page has already
been partially sent – some form of content has been streamed to the
browser – so the ship cannot be turned around in the canal.

The easy fix for this is to include() or require() your PHP script as
the absolute first thing in your document. Use the Before HTML slot of
the Insert / HTML Markup dialog to ensure that you do so. That way,
your logic has time to fire and decide whether or not to redirect the
browser before any content (usually the DOCTYPE, HTML and parts of the
HEAD will be sent before anything else) get streamed to the browser.

Walter

On Apr 27, 2010, at 10:16 AM, hugh wrote:

I’m using a PHP include to pull in a wiki script into a .php page.

It does appear to pull the page in, but without any styling or
formatting, and with the warnings:

"Warning: Cannot modify header information - headers already sent by
(output started at /Volumes/Formac_120Gb_Webserver/HUCKLOW.COM/test/
newsite/wiki.php:6) in /Volumes/Formac_120Gb_Webserver/HUCKLOW.COM/
test/newsite/doku/inc/auth.php on line 313

Warning: Cannot modify header information - headers already sent by
(output started at /Volumes/Formac_120Gb_Webserver/HUCKLOW.COM/test/
newsite/wiki.php:6) in /Volumes/Formac_120Gb_Webserver/HUCKLOW.COM/
test/newsite/doku/inc/actions.php on line 163"

I must admit I don’t understand header information! What does it all
mean?

Hugh


dynamo mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options


dynamo mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Hi Walter,

Right, i see. But what would I need to ‘require’ before the html output starts? I’m including the script somewhere down the page, do I also need to require it first?

Like ?php require_once(‘doku/doku.php’); ?

something like that?


dynamo mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

You want to require the script as the very first possible thing. But
then if your script expects to also output text to the browser, you
may need to refactor that code so that it sets a variable instead, and
then use the print() or echo() commands further down your page to
output that variable’s content.

Here’s a quickie example:

<?php
//include_me.php
if($_SESSION['foo'] != 'bar'){
	header('Location: baz.html');
	exit;
}else{
	print 'Heh heh heh! He said bar!';
}
?>

If you include this in your page somewhere visible, then you would
only see the message if the session variable was already set. In any
other case, you would see the error you got in your system. The reason
is that the code is trying to redirect the browser after some part of
the content has been sent. Can’t do that. Here’s the same script but
broken into two pieces so it won’t fail like that:

<?php
//include_me.php
$message = '';
if($_SESSION['foo'] != 'bar'){
	header('Location: baz.html');
	exit;
}else{
	$message = 'Heh heh heh! He said bar!';
}
?>

Before anything else in your page, above the DOCTYPE, you would:

<?php require('include_me.php'); ?>

Then follows a bunch of HTML and finally:

<?php echo $message; ?>

If the redirection happens, it will happen before any other headers
are sent to the browser. If the redirection doesn’t happen, then the
$message variable will contain a message and will be displayed
wherever you put the echo() statement (and after the usual headers and
other parts of the beginning of the page are sent to the browser).

Walter

On Apr 27, 2010, at 11:19 AM, hugh wrote:

Hi Walter,

Right, i see. But what would I need to ‘require’ before the html
output starts? I’m including the script somewhere down the page, do
I also need to require it first?

Like ?php require_once(‘doku/doku.php’); ?

something like that?


dynamo mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options


dynamo mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Hmmm…I’m lost again. Too many foos and bars.

I’m just rrying to include a complete wiki into the page. The wiki and all it’s files is in /doku, and the start page doku.php. I’ve no idea whether the script 'expects to output text to the browser, but I bloody well hope it would, it’s a wiki!

I’m afraid I don’t understand the purpose of the messages and the foos and stuff, and wouldn’t know how to write it anyway! I just thought (and I have successfully php included scripts before) that a simple PHP include would do it.

Unfortunately an iFrame won’t work here due to all the complex issues surrounding variable page length (I’ve tried before, it’s a mare).

Maybe I should work the other way around and try and include the logo masthead and nav of the site into the script header file?..?? I can see that being a bit more tricky and non-Freeway, but it might be easier?

Hugh


dynamo mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

This would definitely be the easier route, but perhaps the result
would be less definitively your “brand”. I don’t know which Wiki
you’re using here, but it’s probably going to be limited to a banner
graphic, if anything. The rest will be down to hand-editing the CSS
file(s).

If you’re trying to include an entire Wiki into the middle of a
Freeway page, then you’re probably not going to get anywhere anyway,
because it will output its own set of DOCTYPE, HEAD, and BODY tags, so
you’d end up with a page inside a page, which will crash some browsers
and certainly will confuse most.

If you had written the Wiki engine, then the foo and bar and baz would
likely not confuse you at all, and you’d probably not have too much
trouble pointing out the spot where your script stops printing out
template code and starts printing the dynamic content. If that were
the case, you could probably replace the entire template with your
Freeway page, and get what you wanted in the first place.

Walter

On Apr 27, 2010, at 1:08 PM, hugh wrote:

Maybe I should work the other way around and try and include the
logo masthead and nav of the site into the script header file?..??
I can see that being a bit more tricky and non-Freeway, but it might
be easier?


dynamo mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

I might even use a frames page. Not ‘de rigeur’ I know, but might do the business.

The wiki is dokuwiki, not especially heavy on headers and stuff I don’t think, but am using a specific template and dokuwiki has a reasonable set of files to hang together. I just try putting the masthead in the template file, but as the regular masthead also includes javascript navigation I can see myself running into trouble… :wink:

Thanks for taking a look, I really thought php would be easier.

cheers
Hugh


dynamo mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options