Warning: Cannot add header information

Tutorials on PHP, databases and other aspects of web development. Before posting a question, check in here to see whether there's a tutorial that covers your problem.

Moderator: General Moderators

McGruff
DevNet Master
Posts: 2893
Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland

Post by McGruff »

wmasterj wrote:i don't know why but that ob_*() stuff has never worked for me!

oh well!
If you've got a problem with a script read through this topic again, check the php manual, and post in the normal forum if you're still having trouble.
[xNet]DrDre
Forum Newbie
Posts: 8
Joined: Wed Oct 01, 2003 7:06 am

Post by [xNet]DrDre »

there is one way to disable this error!

Code: Select all

<?
@ini_set("output_buffering","On");
?>
Now you can send text before headers and not get an error, such as cookies, this now would be valid

Code: Select all

 
You are now logged in!<? setcookie('LoggedIn','true',time()+3600);?>
 
User avatar
Kriek
Forum Contributor
Posts: 238
Joined: Wed May 29, 2002 3:46 am
Location: Florida
Contact:

Post by Kriek »

This is what I have been utilizing recently.

Code: Select all

<?php 
    ob_start(); 
    if(!headers_sent()) { 
        header("refresh: 1; url=http://www.example.com"); 
    } 
    ob_end_flush(); 
?>
Last edited by Benjamin on Mon May 11, 2009 2:10 am, edited 1 time in total.
Reason: Changed [code] to [code=php]
User avatar
devork
Forum Contributor
Posts: 213
Joined: Fri Aug 08, 2003 6:44 am
Location: p(h) developer's network

Post by devork »

ok
that mini-how-to cleared some concepts for me,watch what you are eching and sending headers.

Does this thing, has anything to do with register_globals in php.ini ?
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

devork wrote:ok
that mini-how-to cleared some concepts for me,watch what you are eching and sending headers.

Does this thing, has anything to do with register_globals in php.ini ?
Nope.

Mac
olaolu
Forum Newbie
Posts: 6
Joined: Tue Jan 13, 2004 3:41 am

Still on Variables

Post by olaolu »

Thanks, your solution works for header() but i still have problem with the session variable :roll:
fuyenhou
Forum Newbie
Posts: 9
Joined: Tue Jun 22, 2004 4:54 am
Location: Malaysia
Contact:

Re: ob_start in relation to cookies

Post by fuyenhou »

moniarde wrote:

Code: Select all

 
<?php
ob_start();
?>
<html>
<body>
<?php
 
echo "testing 1,2,...";
setcookie("testcookie", "test");
 
?>
</body>
</html>
Hope that helps. :D

I am wondering how about show cookie?? can ar?
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: Warning: Cannot add header information

Post by Benjamin »

I've fixed the code formatting in this post and resurrected it from the grave. We get this question a lot around here, so keep in mind where this post is so you can refer to it whenever this question arises.
Post Reply