PHPで「Cannot modify header information - headers already sent by」というエラーになる場合の対処について紹介します。 1.問題点 次のようなPHPを作成しました。 <?php echo("test"); header('Content-Type: application/json; charset=utf-8'); …後略… ?> このPHPを実行したところ、「Cannot modify header information - headers already sent by (output started at /.../index.php:xx) in /.../index.php on line xx」というエラーが発生しました。 2.原因 原因はheader()関数の前にecho文があるためです。 header()はHTT
![PHPで「Cannot modify header information - headers already sent by」というエラーになる場合の対処](https://cdn-ak-scissors.b.st-hatena.com/image/square/a7e3e37d97763d91f5d54319582e693fb96bf262/height=288;version=1;width=512/https%3A%2F%2Fwww.koikikukan.com%2Fimages%2F2016%2Fphp_logo.png)