Warning: Cannot modify header information - headers already sent [duplicate]

。_饼干妹妹 提交于 2019-11-27 08:04:28

问题


This question already has an answer here:

  • How to fix “Headers already sent” error in PHP 11 answers

I get the errormessage: Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\json.php:1)

I know this errormessage will come, if I wrote something and want to send later an header information. But in this case I don't write anything. Here is my code starting at line 1.

<? header("Content-type: text/html; charset=utf-8");

require ("diplom/includes/php/datenbankfunktionen.php");

$sDB_Server   = "localhost";
$sDB_User     = "root";
$sDB_Password = "";
$sDB_Database = "JSON";

$sSql = "SELECT name, phone, mail as email, contactID AS id FROM contact;";
$aContacts = DB_GetSelectArray($sSql);
echo '{"DATA":'.json_encode($aContacts).',"SUCCESS":true,"ERRORS":[]}';
?>

Can somone help me? I use an developer system with XAMPP.


回答1:


You've been had by the utf8 BOM

Basically your file has some strange characters at the beginning of the file to mark it as utf8. This is called a Byte Order Mark and is not shown in most editors but is output by php

.




回答2:


Check if you have a whitespace or empty line before <? header("Content-type: text/html; charset=utf-8"); and remove it.



来源:https://stackoverflow.com/questions/2243087/warning-cannot-modify-header-information-headers-already-sent

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!