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