Jump to content

[SOLVED] headers already sent error, caused by a nested include!??


davestewart

Recommended Posts

Hey all,

I have a bunch of includes I use at the op of each page, and I decided to place them all in a separate file (dbConnect.php), and just include that. The thing is, one of the functions that is within the included includes, even though it isn't executed (!), appears to alter the headers so session_start or header() won't work.

 

Warning: session_start(): Cannot send session cookie - headers already sent by (output started at W:\bill-split\php\dbConnect.php:20) in W:\bill-split\pages\home.php on line 30

 

Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at W:\bill-split\php\dbConnect.php:20) in W:\bill-split\pages\home.php on line 30

Any ideas? It's driving me nuts!

 

Thanks,

Dave :)

Hey Tom,

 

Actually I solved it in the interim. I figured that as my login script was using both sessions and header('location: ') there was going to be a problem.

 

I used ob_clean() in the end and that solves everything, as once the headers are read the page is clean, and I can redirect (sending new headers) if necessary...

 

Many thanks for your input in the meantime though!

Cheers,

Dave

OK, problem NOT SOLVED.

 

This is driving me up the wall now!!! I've been on this for FOUR HOURS!

I'm so sure I'm NOT sending any headers. Basically, if I put the lines of code in an intermediate include, the script appears to send headers which f*cks up my redirect.

 

However, if I include the lines of code in the file, it's FINE!

 

The code is as follows:

 

// settings

include_once '../db/dbSettings.inc.php';

 

// db classes

include_once '../classes/ez_sql_2.03/shared/ez_sql_core.php';

include_once '../classes/ez_sql_2.03/mysql/ez_sql_mysql.php';

 

// connect to database

$link = mysql_connect($dbhost, $dbusername, $dbuserpass);

if (!$link) {

    die("Could not connect to database ...");

}

else{

$db = new ezSQL_mysql($dbusername, $dbuserpass, $dbname, $dbhost);

}

 

As you can see - pretty basic.

 

I have NO IDEA why this is as difficult as it is.

Any help is so welcome, thanks.

Hi Tom,

Well after much testing and refactoring and getting things straight...  your tip does the trick perfectly!

 

This output buffering stuff has been one of those php lightbulb / sun-through-the-clouds moments, so thank you very, very much. It's been a massive help.

 

Cheers,

Dave

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.