title: Session Start PHP error message Cannot send session cache limiter - headers already sent
body: <p>I am using quite a simple php script (login.php) to let a user log in to a protected page. However, I keep getting these error messages </p>
  
  <pre><code>Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at /var/sites/f/mysite.co.uk/public_html/users/login.php:15) in /var/sites/f/mysite.co.uk/public_html/users/login.php on line 36
  
  Warning: Cannot modify header information - headers already sent by (output started at /var/sites/f/freedomprogramme.co.uk/public_html/users/login.php:15) in /var/sites/f/freedomprogramme.co.uk/public_html/users/login.php on line 39
  </code></pre>
  
  <p>and the page won't redirect to the Welcome page, which has this line at the top</p>
  
  <pre><code>&lt;?php
  session_start();
  if(!isset($_SESSION["sess_user"])){
  header("Location: login.php");
  }
  else
  {
  ?&gt;
  </code></pre>
  
  <p>Here are the contents of login.php</p>
  
  <pre><code>&lt;!doctype html&gt;
  &lt;html&gt;
  &lt;head&gt;
  &lt;title&gt;Login&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;h1&gt;Login&lt;/h1&gt;
  &lt;form action="" method="post"&gt;
  &lt;label&gt;Username:&lt;/label&gt;&lt;input type="text" name="user"&gt;&lt;br/&gt;
  &lt;label&gt;Password:&lt;/label&gt;&lt;input type="password" name="pass"&gt;&lt;br/&gt;
  &lt;input type="submit" value="Login" name="submit"&gt;&lt;br/&gt;
  &lt;!--New user Register Link --&gt;
  &lt;p&gt;&lt;a href="register.php"&gt;New User Registration!&lt;/a&gt;&lt;/p&gt;
  &lt;/form&gt;
  &lt;?php
  if(isset($_POST["submit"])){
  if(!empty($_POST['user']) &amp;&amp; !empty($_POST['pass'])){
  $user = $_POST['user'];
  $pass = $_POST['pass'];
  //DB Connection
  $conn = new mysqli('xxxx', 'yyyy', 'zzzz') or die(mysqli_error());
  //Select DB From database
  $db = mysqli_select_db($conn, 'yyyy') or die("databse error");
  //Selecting database
  $query = mysqli_query($conn, "SELECT * FROM userpass WHERE user='".$user." AND pass='".$pass."'");
  $numrows = mysqli_num_rows($query);
  if($numrows !=0)
  {
  while($row = mysqli_fetch_assoc($query))
  {
  $dbusername=$row['user'];
  $dbpassword=$row['pass'];
  }
  if($user == $dbusername &amp;&amp; $pass == $dbpassword)
  {
  session_start();
  $_SESSION['sess_user']=$user;
  //Redirect Browser
  header("Location:welcome.php");
  }
  }
  else
  {
  echo "Invalid Username or Password!";
  }
  }
  else
  {
  echo "Required All fields!";
  }
  }
  ?&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Any help appreciated. Thanks in advance</p>