The Problem With HTTP Headers When Using Include in PHP

The problem with HTTP headers can also occur when including files via include. It manifests itself in the case when after the closing tag ?> there are spaces or blank lines, like this:

file.php<?php
  // some code
?>

 

In this case, when including our file into another file, the left blank lines will act as output to the screen:

index.php<?php
  include 'file.php'; // inside there is output to the screen
  
  header('Content-Type: text/html');
?>

To fix the problem, it is better in all PHP files to remove the last closing ?>. This technique does not lead to a PHP error and at the same time protects us from accidentally adding blank lines. Let's fix our file:

file.php<?php
  // some code
  
   
Задание 1

Fix the errors in the following code:

file1.php<?php
  function func1() {
    echo '1';
  }
?>

 
file1.php<?php
  function func2() {
    echo '2';
  }
?>

 
index.php<?php
  include 'file1.php';
  include 'file2.php';
  header('Content-Type: text/html');
?>

 
Задание 2

Fix the errors in the following code:

file.php<?php
  function func1() {
    echo '1';
  }
?>
<?php
  function func2() {
    echo '2';
  }
?>
 
index.php<?php
  include 'file.php';
  header('Content-Type: text/html');
?>