title: PHP cannot modify header
body: <p>I’m trying to solve a problem with PHP but I can’t find out where my mistake is. If someone can help me please write an answer.</p>
  
  <p>PHP sends the following error message:</p>
  
  <blockquote>
    <p><code>[26-Feb-2014 03:00:46 Europe/Berlin] PHP Warning:  Cannot modify header information - headers already sent by (output started at /Applications/MAMP/htdocs/PressIn_21022014/includes/head.php:2) in /Applications/MAMP/htdocs/PressIn_21022014/recap_commande.php on line 41</code></p>
  </blockquote>
  
  <p>when I click on <code>valider_commande</code>:</p>
  
  <pre><code>&lt;?php
      session_start();
      if(isset($_SESSION['auth']) &amp;&amp; $_SESSION['auth'] == true){
      $document = basename(__FILE__);
      $titre = "Espace Membre";
      include("includes/head.php"); 
  ?&gt;
  
  
    &lt;div class="background col-xs-12 col-sm-12 col-md-12 col-lg-12"&gt;
              &lt;div class="container top"&gt;
              &lt;div class="elements"&gt;
                &lt;form  id="form_top_ten" method="POST" action="recap_commande.php"&gt;
                      &lt;div class="row"&gt;
                          &lt;div class="col-xs-12 col-sm-6 col-md-6 col-lg-6"&gt;
                                  &lt;div class="commande_top_ten"&gt;
                                      &lt;div class="col-xs-3 col-sm-4 col-md-4 col-lg-3"&gt;&lt;h4&gt;Veste&lt;/h4&gt;&lt;/div&gt;
                                        &lt;img src="img/icone_veste.svg" /&gt;
                                        &lt;button id="moins_veste" type="button" class="btn-moins btn-circle btn-mini"&gt;&lt;i class="glyphicon-minus"&gt;&lt;/i&gt; &lt;/button&gt;
                                        &lt;span class="quantite" id="top_ten_nb_veste"&gt;1&lt;/span&gt;
                                        &lt;button id="plus_veste" type="button" class="btn-plus btn-circle btn-mini"&gt;&lt;i class="glyphicon-plus"&gt;&lt;/i&gt; &lt;/button&gt;
                                        &lt;div class="prix"&gt;&lt;span class="prix_pantalon"&gt;  10&lt;/span&gt; €&lt;/div&gt;
                                  &lt;/div&gt;
                          &lt;/div&gt;
                          &lt;div class="col-xs-12 col-sm-6 col-md-6 col-lg-6"&gt;
                                  &lt;div class="commande_top_ten"&gt;
                                      &lt;div class="col-xs-3 col-sm-4 col-md-4 col-lg-3"&gt;&lt;h4&gt;Pantalon&lt;/h4&gt;&lt;/div&gt;
                                      &lt;img src="img/icone_pant.svg" /&gt;
                                      &lt;button id="moins_pantalon" type="button" class="btn-moins btn-circle btn-mini"&gt;&lt;i class="glyphicon-minus"&gt;&lt;/i&gt; &lt;/button&gt;
                                      &lt;span class="quantite" id="top_ten_nb_pantalon"&gt;1&lt;/span&gt;
                                      &lt;button id="plus_pantalon" type="button" class="btn-plus btn-circle btn-mini"&gt;&lt;i class="glyphicon-plus"&gt;&lt;/i&gt; &lt;/button&gt;
                                      &lt;div class="prix"&gt;&lt;span class="prix_pantalon"&gt;  10&lt;/span&gt; €&lt;/div&gt;
  
                                  &lt;/div&gt;
                          &lt;/div&gt;
                      &lt;/div&gt;
                      &lt;div class="row"&gt;
                          &lt;div class="col-xs-12 col-sm-6 col-md-6 col-lg-6"&gt;
                                  &lt;div class="commande_top_ten"&gt;
                                      &lt;div class="col-xs-3 col-sm-4 col-md-4 col-lg-3"&gt;&lt;h4&gt;Chemise&lt;/h4&gt;&lt;/div&gt;
                                      &lt;img src="img/icone_chemise.svg" /&gt;
                                      &lt;button id="moins_chemise" type="button" class="btn-moins btn-circle btn-mini"&gt;&lt;i class="glyphicon-minus"&gt;&lt;/i&gt; &lt;/button&gt;
                                      &lt;span class="quantite" id="top_ten_nb_chemise"&gt;1&lt;/span&gt;
                                      &lt;button id="plus_chemise" type="button" class="btn-plus btn-circle btn-mini"&gt;&lt;i class="glyphicon-plus"&gt;&lt;/i&gt; &lt;/button&gt;
                                      &lt;div class="prix"&gt;&lt;span class="prix_pantalon"&gt;  10&lt;/span&gt; € &lt;/div&gt;
  
                                  &lt;/div&gt;
                          &lt;/div&gt;
                          &lt;div class="col-xs-12 col-sm-6 col-md-6 col-lg-6"&gt;
                                  &lt;div class="commande_top_ten"&gt;
                                      &lt;div class="col-xs-3 col-sm-4 col-md-4 col-lg-3"&gt;&lt;h4&gt;Robe&lt;/h4&gt;&lt;/div&gt;
                                      &lt;img src="img/icone_robe.svg" /&gt;
                                      &lt;button id="moins_robe" type="button" class="btn-moins btn-circle btn-mini"&gt;&lt;i class="glyphicon-minus"&gt;&lt;/i&gt; &lt;/button&gt;
                                      &lt;span class="quantite" id="top_ten_nb_robe"&gt;1&lt;/span&gt;
                                      &lt;button id="plus_robe" type="button" class="btn-plus btn-circle btn-mini"&gt;&lt;i class="glyphicon-plus"&gt;&lt;/i&gt; &lt;/button&gt;
                                      &lt;div class="prix"&gt;&lt;span class="prix_pantalon"&gt;  10&lt;/span&gt; €&lt;/div&gt;
  
                                  &lt;/div&gt;
                          &lt;/div&gt;
                      &lt;/div&gt;
                      &lt;div class="row"&gt;
                          &lt;div class="col-xs-12 col-sm-6 col-md-6 col-lg-6"&gt;
                                  &lt;div class="commande_top_ten"&gt;
                                      &lt;div class="col-xs-3 col-sm-4 col-md-4 col-lg-3"&gt;&lt;h4&gt;Manteau&lt;/h4&gt;&lt;/div&gt;
                                      &lt;img src="img/icone_manteau.svg" /&gt;
                                      &lt;button id="moins_manteau" type="button" class="btn-moins btn-circle btn-mini"&gt;&lt;i class="glyphicon-minus"&gt;&lt;/i&gt; &lt;/button&gt;
                                      &lt;span class="quantite" id="top_ten_nb_manteau"&gt;1&lt;/span&gt;
                                      &lt;button id="plus_manteau" type="button" class="btn-plus btn-circle btn-mini"&gt;&lt;i class="glyphicon-plus"&gt;&lt;/i&gt; &lt;/button&gt;
                                      &lt;div class="prix"&gt;&lt;span class="prix_pantalon"&gt;  10&lt;/span&gt; € &lt;/div&gt;
  
                                  &lt;/div&gt;
                          &lt;/div&gt;
                          &lt;div class="col-xs-12 col-sm-6 col-md-6 col-lg-6"&gt;
                                  &lt;div class="commande_top_ten"&gt;
                                      &lt;div class="col-xs-3 col-sm-4 col-md-4 col-lg-3"&gt;&lt;h4&gt;Veste&lt;/h4&gt;&lt;/div&gt;
                                      &lt;img src="img/icone_pant.svg" /&gt;
                                      &lt;button type="button" class="btn-moins btn-circle btn-mini"&gt;&lt;i class="glyphicon-minus"&gt;&lt;/i&gt; &lt;/button&gt;
                                      &lt;span class="quantite" id="top_ten_nb_veste"&gt;1&lt;/span&gt;
                                      &lt;button type="button" class="btn-plus btn-circle btn-mini"&gt;&lt;i class="glyphicon-plus"&gt;&lt;/i&gt; &lt;/button&gt;
                                      &lt;div class="prix"&gt;&lt;span class="prix_pantalon"&gt;  10&lt;/span&gt; €&lt;/div&gt;
  
                                  &lt;/div&gt;
                          &lt;/div&gt;
                      &lt;/div&gt;
                      &lt;div class="row"&gt;
                          &lt;div class="row col-xs-12 col-sm-6 col-md-6 col-lg-6"&gt;
                                  &lt;div class="commande_top_ten"&gt;
                                      &lt;div class="col-xs-3 col-sm-4 col-md-4 col-lg-3"&gt;&lt;h4&gt;Pull&lt;/h4&gt;&lt;/div&gt;
                                      &lt;img src="img/icone_pull.svg" /&gt;
                                      &lt;button id="moins_pull" type="button" class="btn-moins btn-circle btn-mini"&gt;&lt;i class="glyphicon-minus"&gt;&lt;/i&gt; &lt;/button&gt;
                                      &lt;span class="quantite" id="top_ten_nb_pull"&gt;1&lt;/span&gt;
                                      &lt;button id="plus_pull" type="button" class="btn-plus btn-circle btn-mini"&gt;&lt;i class="glyphicon-plus"&gt;&lt;/i&gt; &lt;/button&gt;
                                      &lt;div class="prix"&gt;&lt;span class="prix_pantalon"&gt;  10&lt;/span&gt; €&lt;/div&gt;
  
                                  &lt;/div&gt;
                          &lt;/div&gt;
                          &lt;div class="row col-xs-12 col-sm-6 col-md-6 col-lg-6"&gt;
                                  &lt;div class="commande_top_ten"&gt;
                                      &lt;div class="col-xs-3 col-sm-4 col-md-4 col-lg-3"&gt;&lt;h4&gt;Jupe&lt;/h4&gt;&lt;/div&gt;
                                      &lt;img src="img/icone_jupe.svg" /&gt;
                                      &lt;button id="moins_jupe" type="button" class="btn-moins btn-circle btn-mini"&gt;&lt;i class="glyphicon-minus"&gt;&lt;/i&gt; &lt;/button&gt;
                                      &lt;span class="quantite" id="top_ten_nb_jupe"&gt;1&lt;/span&gt;
                                      &lt;button id="plus_jupe" type="button" class="btn-plus btn-circle btn-mini"&gt;&lt;i class="glyphicon-plus"&gt;&lt;/i&gt; &lt;/button&gt;
                                      &lt;div class="prix"&gt;&lt;span class="prix_pantalon"&gt;  10&lt;/span&gt; €&lt;/div&gt;
  
                                  &lt;/div&gt;
                          &lt;/div&gt;
                      &lt;/div&gt;
                      &lt;div class="row"&gt;
                          &lt;div class="col-xs-12 col-sm-6 col-md-6 col-lg-6"&gt;
                                  &lt;div class="commande_top_ten"&gt;
                                      &lt;div class="col-xs-3 col-sm-4 col-md-4 col-lg-3"&gt;&lt;h4&gt;Draps&lt;/h4&gt;&lt;/div&gt;
                                      &lt;img src="img/icone_drap.svg" /&gt;
                                      &lt;button type="moins_drap" class="btn-moins btn-circle btn-mini"&gt;&lt;i class="glyphicon-minus"&gt;&lt;/i&gt; &lt;/button&gt;
                                      &lt;span class="quantite" id="top_ten_nb_drap"&gt;1&lt;/span&gt;
                                      &lt;button type="plus_drap" class="btn-plus btn-circle btn-mini"&gt;&lt;i class="glyphicon-plus"&gt;&lt;/i&gt; &lt;/button&gt;
                                      &lt;div class="prix"&gt;&lt;span class="prix_drap"&gt;  10&lt;/span&gt; €&lt;/div&gt;
  
                                  &lt;/div&gt;
                          &lt;/div&gt;
                          &lt;div class="col-xs-12 col-sm-6 col-md-6 col-lg-6"&gt;
                                  &lt;div class="commande_top_ten"&gt;
                                      &lt;div class="col-xs-3 col-sm-4 col-md-4 col-lg-3"&gt;&lt;h4&gt;Chemise&lt;/h4&gt;&lt;/div&gt;
                                      &lt;img src="img/icone_chemisepliee.svg" /&gt;
                                      &lt;button type="moins_drap" class="btn-moins btn-circle btn-mini"&gt;&lt;i class="glyphicon-minus"&gt;&lt;/i&gt; &lt;/button&gt;
                                      &lt;span class="quantite" id="top_ten_nb_drap"&gt;1&lt;/span&gt;
                                      &lt;button type="plus_drap" class="btn-plus btn-circle btn-mini"&gt;&lt;i class="glyphicon-plus"&gt;&lt;/i&gt; &lt;/button&gt;
                                      &lt;div class="prix"&gt;&lt;span class="prix_pantalon"&gt;  10&lt;/span&gt; €&lt;/div&gt;
                                  &lt;/div&gt;
                          &lt;/div&gt;
                      &lt;/div&gt;
  
                      &lt;button type ="submit" class="btn_valider btn btn-danger col-xs-9 col-sm-6 col-md-6 col-lg-4" name="valider_commande" value="valider_commande"&gt;&lt;i class="glyphicon glyphicon-shopping-cart"&gt;&lt;/i&gt;Valider commande (' .$prix_total. ' euros)&lt;/button&gt;
                    &lt;/form&gt;
                  &lt;/div&gt;
                  &lt;/div&gt;
                  &lt;?php
                    if (!empty($_SESSION['form_top_ten'])){
                        $nb_articles = sizeof($_SESSION['commande_top_ten']);
                        $prix_total = 0;
                        for ($i=0;$i&lt;$nb_articles;$i++){
                          $prix_total += $_SESSION['commande_top_ten'][$i]['prix'];
                        }
                    }
  
                  ?&gt;
          &lt;/div&gt;
    &lt;?php 
        }
        else{
          header('Location:auth_form.php');
        }
      ?&gt;
  </code></pre>
  
  <p>This is <strong>head.php</strong> line 2:</p>
  
  <pre><code>&lt;head&gt;
      **&lt;title&gt;E-Pressing - &lt;?php echo $titre; ?&gt;&lt;/title&gt;**
      &lt;link href="css/bootstrap.css" rel="stylesheet"&gt;  
      &lt;meta charset="UTF-8"&gt;
      &lt;link href="css/business-frontpage.css" rel="stylesheet"&gt;
      &lt;link href='http://fonts.googleapis.com/css?family=Poiret+One' rel='stylesheet' type='text/css'&gt;
      &lt;link href='http://fonts.googleapis.com/css?family=Lato:100,300,400,700,900,100italic,300italic,400italic,700italic,900italic' rel='stylesheet' type='text/css'&gt;
      &lt;meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"&gt;
  &lt;/head&gt;
  </code></pre>
  
  <p>Thanks for your help!</p>