Cannot modify header information - headers already sent by... ?
I know a fix for this, set output_buffering = off in php.ini, but i've read that,
Quote:
that header() must be before any output
so is there any bad effect from setting, output_buffering = off ?
Re: Cannot modify header information - headers already sent by... ?
no, there isn't a fix like that for it. you can't send new headers (cookies, location redirects, etc) after you've already sent some kind of output to the user. you must rearrange the way your script executes and do anything like setting cookies before ANY output is sent to the user.
this will not work:
PHP Code:
<?php
echo 'welcome to my website';
setcookie('name', 'value', time()+5*60);
?>
while this will:
PHP Code:
<?php
setcookie('name', 'value', time()+5*60);
echo 'welcome to my website';
?>
Re: Cannot modify header information - headers already sent by... ?
thats just not true, i actually meant to say, set,
Quote:
output_buffering = on
not,
Quote:
output_buffering = off
which does let you do what you say you can't , try it!
i just need to know if there is a downsid to this, i think i may have read something a while ago that the greater the value you set output_buffering the slower php handles...?
Re: Cannot modify header information - headers already sent by... ?
oh. well, you originally said it was off -- so there's not really any way around that unless you're using output buffering (either by manually setting it in the php.ini file, or by using ob_start()).
well. I'm not really sure of a downside. I think ASP uses a form of output buffering by default. from everything I've read, it's a good idea in some cases. one common use is compression. you could use up to about 40% less bandwidth by compressing your pages (as long as they're more text-based than image-based, of course), although it will take more CPU processing to actually compress it. you'll save on CPU cycles spent sending the pages (because you'll have less to send), though.
one note: I'd probably not recommend using output buffering as a work around! logic and presentation should be separate (direct quote from penagate, haha).
you could take a look at this article on output buffering if you'd like. and I'd look into using the output buffering functions built into PHP rather than having the option set in the php.ini. it will probably give you a lot more flexibility overall. you can also check out the PHP manual's references for all of the functions for more information here (the comments are useful, too).