Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

include(); problem 1

Status
Not open for further replies.

overyde

Programmer
May 27, 2003
226
ZA
Hi,
I have a file with the dbase connection details which I call into my script using: include("config.php");

Problem is that when I need to include a page redirection, namely:
header("Location: other_page.php");

I get an error saying that headers were already sent from the line with the include("config.php");

How do i get around this so I don't have to write out the dbase connections everytime I need to have a
header("Location: other_page.php");

P.S. No one seems to hand out stars anymore!!!!

Reality is built on a foundation of dreams.
 
in your config.php place this line at the top of your page:

ob_start(); //Start buffering output. you can stop it whenever you want to...

Known is handfull, Unknown is worldfull
 
What are you outputting in the file with the database connections? Basically, if everything goes ok, script usually outputs nothing. There could be some whitespace before your opening <?php in any of the files (main file or included file) that could cause that error. You can have as much code as you want before the header() call as long as you don't output anything (print or echo).
 
I agree with Vragabond. Something must have been output before the header() is called. Whitespace is the most common culprit.
 
As far as I recall, there was output, but it was neccessary to have it...I think. Any other work around solution?

Reality is built on a foundation of dreams.
 
the ob_start() will work fine...

Known is handfull, Unknown is worldfull
 
Just to clarify:

Outputting something and then redirecting is not an option, not with headers. Once output has been sent headers can't be sent.

If there is output that has to be displayed first - header() will not be an option. You can do some client side solution, which of course may work or not, depending on the client. Meta refresh tags, or client side scripting, but no PHP solution.

Maybe you can give a bit more detail what it is you want to do ith this, so we can make more useful suggestions.
 
SPot on VBKRIS...
Thanks!!!

Reality is built on a foundation of dreams.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top