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