title: session_start errors because 'headers already sent' by the same session_start action?
body: <p>I am trying to start a session in PHP in order to store data about a user ID (which will be used in mySQL DB).</p>
  
  <p>However when I start the session I get the following errors:</p>
  
  <pre><code>Warning: session_start(): Cannot send session cookie - headers already sent by (output started at /Applications/MAMP/blah) in /Applications/MAMP/blah on line 38
  
  Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at /Applications/MAMP/blah) in /Applications/MAMP/blah on line 38
  </code></pre>
  
  <p>I understand that the error is saying it cannot start the session as the page is already submitted, or "header already sent" however I am very confused because the line it is referencing, line 38, IS the line that starts the session:</p>
  
  <pre><code>Line 38: session_start();
  </code></pre>
  
  <p>So how can it say the headers are already sent by this line and that's the error?</p>
  
  <p>Here is a shortened down section of my code. To note, there is  portion of the HTML that is loaded in via AJAX using jQuery, could that be it?</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;head&gt;
  &lt;title&gt;Title&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
          &lt;div class="wrapper"&gt;
            &lt;div id="quiz-section"&gt;
               // This part is where the HTML content loads via AJAX
            &lt;/div&gt;
          &lt;/div&gt;
  &lt;!-- Below PHP looks at the referral i.e how the user landed on this page --&gt;
  &lt;?php
  session_start();
  require 'connect.php';
  if (!mysqli_query($con,"INSERT INTO entries (referral) VALUES ('$ref')")){
          echo("Error description: " . mysqli_error($con));
          return false;
  }
  
  $_SESSION["sessionID"] = mysqli_insert_id($con);
  mysqli_close($con);
  
  ?&gt;
  &lt;/body&gt;
  
  &lt;script&gt;
  // some jQuery here to load in the HTML content to the AJAX pane   
  &lt;/script&gt;
  &lt;/html&gt;
  </code></pre>