• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Cannot modify header information - headers already sent

#1
[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.

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

#3
[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");

#4
[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);

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

#6
[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?

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

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

#9
[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.

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


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.