可能重复:
“Warning: Cannot modify header information - headers already sent by” error
Headers already sent by PHP
我发出警告说:
Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\projects\wesm\intranet\plugins\company_calendar\calendarpdf.php:90) in C:\xampp\htdocs\projects\wesm\intranet\plugins\company_calendar\mpdf\mpdf.php on line 7236
Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\projects\wesm\intranet\plugins\company_calendar\calendarpdf.php:90) in C:\xampp\htdocs\projects\wesm\intranet\plugins\company_calendar\mpdf\mpdf.php on line 1827
mPDF error: Some data has already been output to browser, can't send PDF file
你可以给我一些建议来摆脱那些警告..
以下是我的一些代码:
<?php
include "admin/include/connect.php";
include "include/calendarFunction.php";
$function = new calendarFunction();
$cMonth = $_GET['cMonth'];
$cYear = $_GET['cYear'];
$htmldata = $function->calendarPDF($cMonth, $cYear);
$currString = $htmldata;
$stringtoDelete = '';
$newCurrString = str_replace($stringtoDelete, " ", $currString);
$html = $newCurrString ;
include("mpdf/mpdf.php");
$mpdf=new mPDF();
$mpdf->AddPage('L');
$mpdf->WriteHTML($html);
$mpdf->Output('calendar.pdf','I');
exit;
?>
答案 0 :(得分:4)
如果在标题之前使用echo,则会出现此错误。
例如:
<?php
echo "Some String";
header("location:redirect.php");
?>
你需要在文件中的任何其他内容之前发送标题,包括php
之外的html<?php
header("location:redirect.php");
echo "Some String";
?>
答案 1 :(得分:3)
请先检查标题功能之前是否有空格,或者在页面调用标题功能之前检查"echo"
。