CodeIgniter Forums
Cannot modify header information - headers already sent - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Cannot modify header information - headers already sent (/showthread.php?tid=41173)

Pages: 1 2


Cannot modify header information - headers already sent - El Forum - 04-30-2011

[eluser]Sudz[/eluser]
A PHP Error was encountered

Severity: Warning

Message: Cannot modify header information - headers already sent

Filename: helpers/my_userExel_helper.php

Line Number: 489

Hi buddy most of the time i found above error
Can someone give me appropriate solution for it.


Cannot modify header information - headers already sent - El Forum - 04-30-2011

[eluser]toopay[/eluser]
Post the line 489 of your exel helper.


Cannot modify header information - headers already sent - El Forum - 04-30-2011

[eluser]Sudz[/eluser]
[quote author="toopay" date="1304166589"]Post the line 489 of your exel helper.[/quote]


On all these lines same error error comes

486
Code:
header("Content-type: application/zip");
487
Code:
header("Content-Disposition: attachment; filename=$archive_file_name");
488
Code:
header("Pragma: no-cache");
489
Code:
header("Expires: 0");



Cannot modify header information - headers already sent - El Forum - 04-30-2011

[eluser]toopay[/eluser]
put this, right BEFORE line 486 :
Code:
if(headers_sent($from, $line)) die ('Headers were already sent at : '.$from.' on line : '.$line);



Cannot modify header information - headers already sent - El Forum - 04-30-2011

[eluser]Sudz[/eluser]
I got this output : Headers were already sent at : on line : 0


Cannot modify header information - headers already sent - El Forum - 04-30-2011

[eluser]Sudz[/eluser]
[quote author="Sudhakar Prajapati" date="1304168206"]I got this output : Headers were already sent at : on line : 0[/quote]


Here is my code
Code:
ob_start();
$objWriter->save('php://output');
$file_name = ob_get_contents();
ob_end_clean();
                
zipFilesAndDownload($file_name,'./user_data/leads.zip');

function zipFilesAndDownload($file_name,$archive_file_name)
    {
          //create the object
          $zip = new ZipArchive();
          //create the file and throw the error if unsuccessful
          if ($zip->open($archive_file_name, ZIPARCHIVE::CREATE )!==TRUE) {
            exit("cannot open <$archive_file_name>\n");
              }
          //add each files of $file_name array to archive
                
          $zip->addFromString("leads/export.xls",$file_name);
          $zip->close();
           //then send the headers to force download the zip file
                
        header('Content-Type: application/vnd.ms-excel');
        header("Content-Disposition: attachment;filename=$archive_file_name");
        header('Cache-Control: max-age=0');
        header("Content-Transfer-Encoding: binary");
        header('Pragma: public');
        readfile($archive_file_name);
         exit;
}

What i am missing?


Cannot modify header information - headers already sent - El Forum - 04-30-2011

[eluser]Sudz[/eluser]
Please help me,no one is there?


Cannot modify header information - headers already sent - El Forum - 04-30-2011

[eluser]toopay[/eluser]
ob_end_clean() does discard headers! any buffers will have already been sent out to the client.


Cannot modify header information - headers already sent - El Forum - 04-30-2011

[eluser]Sudz[/eluser]
[quote author="toopay" date="1304178642"]ob_end_clean() does discard headers! any buffers will have already been sent out to the client.[/quote]


Then Instead of ob_end_clean() what can i use?
I use that to clear buffer after reading buffer contents,
Is there any another alternative.


Cannot modify header information - headers already sent - El Forum - 04-30-2011

[eluser]toopay[/eluser]
try ob_end_flush() instead ob_end_clean()