Page 1 of 1

Headers sent woes : ob_start()??

Posted: Sat Sep 24, 2005 6:16 am
by facets
Hey Gang,

Am getting the following error :
Warning: Cannot modify header information - headers already sent by (output started at c:\program files\easyphp1-8\www\collotype\materialsregister\template.inc:622) in c:\program files\easyphp1-8\www\collotype\includes\functions.inc.php on line 1415

and i haven't figured how to use ob_start() yet.
any ideas?

the code for the query works fine if I remove the headers.
I wish to make the browser compile and 'save' the csv contents to the desktop etc.

Code: Select all

function exportCSV () {
    
ob_start();

header("Content-type: application/octet-stream");
header("Content-disposition: attachment; filename=Materials-".date("d-m-Y").".csv");
header("Pragma: no-cache");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Expires: 0");

$query = ("SELECT *, aupapercategory.paperCategory FROM ausapapersummary
LEFT JOIN aupapercategory ON ausapapersummary.paperCategoryId = aupapercategory.papercategoryId
LEFT JOIN austock ON ausapapersummary.stockId = austock.StockId
LEFT JOIN auadhesive ON ausapapersummary.adhesiveId = auadhesive.adhesiveId
LEFT JOIN auliner ON ausapapersummary.linerId = auliner.linerId
LEFT JOIN ausupplier ON ausapapersummary.supplierId = ausupplier.supplierId
LEFT JOIN ausuitability ON ausapapersummary.suitabilityFoil = ausuitability.suitabilityId
LEFT JOIN admins ON ausapapersummary.ausapaperUserId = admins.id WHERE 1=1");

// Execute SQL Query
$result = mysql_query($query);   

// Error SQL Query
if(!$result) error_message(sql_error());

// While loop for SQL output
while($query_data = mysql_fetch_array($result)) {
$summaryId = $query_data['summaryId'];
$paperCategoryId = $query_data['paperCategoryId'];
$colloPaperName = $query_data['colloPaperName'];
$manufacturerName = $query_data['manufacturerName'];
$cpl = $query_data['cpl'];

echo "$colloPaperName,", "$paperCategory,", "$manufacturerName,", "$supplier,", "$availability,", "$features,", "$limitations,", "$productExamples\n";

    }
}

Posted: Sat Sep 24, 2005 6:34 am
by shiznatix
this horse has been beaten so many times that its just a puddle of mushy blood

viewtopic.php?t=1157

don't use ob_start() to supress those errors. bad coding practice. but if you still wanna be bad then remember that ob_start(); has to be on the 1st line of the script to work like that, not inside a function or whatnot.

Posted: Sat Sep 24, 2005 6:49 am
by facets
if I put it at the top of my index page, where the function gets triggered from, it works but exports the index page content as well as the exportCSV code.
how would i surpress the index page code??

Posted: Sat Sep 24, 2005 6:56 am
by shiznatix
rrrrrread the post that i linked there.

are you trying to do 2 different content type headers? if so i don't think you can do that on 1 page, my work around would be a iframe but maybe you can do 2 different content types.