davestewart Posted February 21, 2007 Share Posted February 21, 2007 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 Link to comment https://forums.phpfreaks.com/topic/39387-solved-headers-already-sent-error-caused-by-a-nested-include/ Share on other sites More sharing options...
tom100 Posted February 21, 2007 Share Posted February 21, 2007 You could try putting this at the top of the page: ob_start(); This basically says that nothing will be outputted until the end of the scripts execution or when the user says so. Put this at the bottom: ob_end_flush(); Link to comment https://forums.phpfreaks.com/topic/39387-solved-headers-already-sent-error-caused-by-a-nested-include/#findComment-189976 Share on other sites More sharing options...
davestewart Posted February 21, 2007 Author Share Posted February 21, 2007 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 Link to comment https://forums.phpfreaks.com/topic/39387-solved-headers-already-sent-error-caused-by-a-nested-include/#findComment-190023 Share on other sites More sharing options...
davestewart Posted February 21, 2007 Author Share Posted February 21, 2007 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. Link to comment https://forums.phpfreaks.com/topic/39387-solved-headers-already-sent-error-caused-by-a-nested-include/#findComment-190153 Share on other sites More sharing options...
tom100 Posted February 21, 2007 Share Posted February 21, 2007 Any output will automatically send headers, even if your not sending headers yourself. Therefore, if you put the code I recommended at the absolute top and bottom of the page respectively, you should have no problem. Link to comment https://forums.phpfreaks.com/topic/39387-solved-headers-already-sent-error-caused-by-a-nested-include/#findComment-190155 Share on other sites More sharing options...
davestewart Posted February 21, 2007 Author Share Posted February 21, 2007 Hey Tom, It's ridiculously late here, so I'll check it out tomorrow. Thanks muchly for your help, Cheers, Dave Link to comment https://forums.phpfreaks.com/topic/39387-solved-headers-already-sent-error-caused-by-a-nested-include/#findComment-190169 Share on other sites More sharing options...
davestewart Posted February 22, 2007 Author Share Posted February 22, 2007 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 Link to comment https://forums.phpfreaks.com/topic/39387-solved-headers-already-sent-error-caused-by-a-nested-include/#findComment-191311 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.