title: CodeIgniter - A session had already been started - ignoring session_start()
body: <p>I keep getting this error:</p>
  
  <blockquote>
    <p>A PHP Error was encountered</p>
    
    <p>Severity: Notice</p>
    
    <p>Message: A session had already been started - ignoring session_start()</p>
    
    <p>Filename: Session/Session.php</p>
    
    <p>Line Number: 140</p>
  </blockquote>
  
  <p>On a page with this code:</p>
  
  <pre><code>&lt;body&gt;
  &lt;p&gt;&lt;a href="&lt;?php echo site_url("Login_controller")?&gt;"&gt;LOGIN&lt;/a&gt;&lt;p&gt; 
  &lt;?php echo $this-&gt;session-&gt;userdata('Username'); ?&gt;
  &lt;/body&gt;
  </code></pre>
  
  <p>There is no session_start() on the page.</p>
  
  <p>The only thing I can think has caused this is in autoload.php i have done this:</p>
  
  <pre><code>$autoload['libraries'] = array('database','session');
  </code></pre>
  
  <p>What is causing this error?</p>
  
  <p>Edit: Login controller</p>
  
  <pre><code>    &lt;?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  
  class Login_controller extends CI_Controller {
      function __construct()
      {
          parent::__construct();
          $this-&gt;load-&gt;model('User_model','',TRUE);
      }
  
  
      function index() //Default function that is run when this controller is called.//
      {
          $this-&gt;load-&gt;helper(array('form'));
          $this-&gt;load-&gt;view('Login_view');
      }
  
  
      function Login()
      {
          $this-&gt;load-&gt;library('form_validation'); 
          $this-&gt;form_validation-&gt;set_rules('Username', 'Username', 'trim|required');
          $this-&gt;form_validation-&gt;set_rules('Password', 'Password', 'trim|required|callback_CheckDatabase');
  
          if($this-&gt;form_validation-&gt;run() == FALSE)
          {
              $this-&gt;load-&gt;view('Login_view'); //Reloads the login view with validation errors if the login attempt is unsuccessful.//
          }
  
          else
          { 
              redirect('Home_controller'); //Redirect to the homepage on successful login attempt.//
          }
      }
  
  
      function CheckDatabase($password) //This function is only run when password validation is correct.//
      {
          $username = $this-&gt;input-&gt;post('Username'); //Sets the username as a $username.//
          $result = $this-&gt;User_model-&gt;Login($username, $password);
  
          if($result)
          {
              $sess_array = array();
              foreach($result as $row)
              {
                  $sess_array = array( //Makes an array of the data to be stored in the session.//
                  'UserID' =&gt; $row-&gt;UserID,
                  'Username' =&gt; $row-&gt;Username
                  );
  
                  $this-&gt;session-&gt;set_userdata('logged_in', $sess_array); //Sets $sess_array as the session.//
              }
  
              return TRUE;
         }
  
          else //Ran if the username or password aren't matched in the CIUsers database. Returns error message.//
          {
              $this-&gt;form_validation-&gt;set_message('CheckDatabase', 'Invalid login details.');
              return false;
          }
      }
  }
  ?&gt;
  </code></pre>