title: error session_start(): Cannot send session cookie - headers already sent by -- in my codeigniter
body: <p><a href="https://i.stack.imgur.com/owmLP.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/owmLP.png" alt="enter image description here"></a></p>
  
  <p>i am working on codeiniter i upload the my file to server but it gives me this error. the same code run correctly on localhost. so what the wrong in my code.</p>
  
  <p>This is the controller</p>
  
  <pre><code>    &lt;?php
  
  class Login extends CI_Controller {
  
      function Index()
      {
          $data['Main_content'] = 'Login_form';
              //$this-&gt;load-&gt;view('header2');
          $this-&gt;load-&gt;view('Includes/Template', $data);  
          //$this-&gt;load-&gt;view('footer');  
      }
  
      function Validate_credentials()
      {       
          $this-&gt;load-&gt;model('Membership_model');
          $query = $this-&gt;Membership_model-&gt;Validate();
  
          if($query) // if the user's credentials validated...
          {
              $data = array(
                  'username' =&gt; $this-&gt;input-&gt;post('username'),
                  'Is_logged_in' =&gt; true
              );
              $this-&gt;session-&gt;set_userdata($data);
              redirect('Site/Members_area');
          }
          else // incorrect username or password
          {
              $this-&gt;index();
          }
      }   
  
      function Signup()
      {
          $data['Main_content'] = 'Signup_form';
          $this-&gt;load-&gt;view('Includes/Template', $data);
      }
  
      function Create_member()
      {
          $this-&gt;load-&gt;library('form_validation');
  
          // field name, error message, validation rules
          $this-&gt;form_validation-&gt;set_rules('first_name', 'Name', 'trim|required');
          $this-&gt;form_validation-&gt;set_rules('last_name', 'Last Name', 'trim|required');
          $this-&gt;form_validation-&gt;set_rules('email_address', 'Email Address', 'trim|required|valid_email');
          $this-&gt;form_validation-&gt;set_rules('username', 'Username', 'trim|required|min_length[4]');
          $this-&gt;form_validation-&gt;set_rules('password', 'Password', 'trim|required|min_length[4]|max_length[32]');
          $this-&gt;form_validation-&gt;set_rules('password2', 'Password Confirmation', 'trim|required|matches[password]');
  
  
          if($this-&gt;form_validation-&gt;run() == FALSE)
          {
  
              $data['Main_content'] = 'Signup_form';
              $this-&gt;load-&gt;view('Includes/Template', $data);
  
  
  
  
          }
  
          else
          {           
              $this-&gt;load-&gt;model('Membership_model');
  
              if($query = $this-&gt;Membership_model-&gt;Create_member())
              {
                  $data['Main_content'] = 'Signup_successful';
                  $this-&gt;load-&gt;view('Includes/Template', $data);
              }
              else
              {
                  $this-&gt;load-&gt;view('Signup_form');           
              }
          }
  
      }
  
      function Logout()
      {
          $this-&gt;session-&gt;sess_destroy();
          $this-&gt;Index();
      }
  
  }
  </code></pre>
  
  <p>this is the site controller </p>
  
  <pre><code>&lt;?php
  
  class Site extends CI_Controller 
  {
      function __construct()
      {
          parent::__construct();
          $this-&gt;Is_logged_in();
  
      }
  
      // function status()
      // {
      //  $this-&gt;load-&gt;model("Emp_model");
      //  $data['showEmployeeTable']=$this-&gt;Emp_model-&gt;selectEmployeeData5();
  
      //      $this-&gt;load-&gt;view('header',$data);
      //  $this-&gt;load-&gt;view('dashboard');
      //  $this-&gt;load-&gt;view('footer');
  
  
      // }
  
      function Members_area()
      {
          //$this-&gt;load-&gt;view('logged_in_area');
  
  
              $this-&gt;load-&gt;view('Header');
          $this-&gt;load-&gt;view('Dashboard');
          $this-&gt;load-&gt;view('Footer');
  
      }
  
      function Another_page() // just for sample
      {
          echo 'good. you\'re logged in.';
      }
  
      function Is_logged_in()
      {
          $Is_logged_in = $this-&gt;session-&gt;userdata('Is_logged_in');
          if(!isset($Is_logged_in) || $Is_logged_in != true)
          {
  
  
              echo 'You don\'t have permission to access this page. &lt;a href="../login"&gt;Login&lt;/a&gt;';    
              die();  
  
              //$this-&gt;load-&gt;view('login_form');
          }       
      }   
  
  }
  </code></pre>
  
  <p>this is the model</p>
  
  <pre><code>class Membership_model extends CI_Model {
  
      function Validate()
      {
          $this-&gt;db-&gt;where('username', $this-&gt;input-&gt;post('username'));
          $this-&gt;db-&gt;where('password', md5($this-&gt;input-&gt;post('password')));
          $query = $this-&gt;db-&gt;get('membership');
  
          if($query-&gt;num_rows() == 1)
          {
              return true;
          }
  
      }
  
      function Create_member()
      {
  
          $new_member_insert_data = array(
              'first_name' =&gt; $this-&gt;input-&gt;post('first_name'),
              'last_name' =&gt; $this-&gt;input-&gt;post('last_name'),
              'email_address' =&gt; $this-&gt;input-&gt;post('email_address'),         
              'username' =&gt; $this-&gt;input-&gt;post('username'),
              'password' =&gt; md5($this-&gt;input-&gt;post('password'))                       
          );
  
          $insert = $this-&gt;db-&gt;insert('membership', $new_member_insert_data);
          return $insert;
      }
  }
  </code></pre>
  
  <p>THIS IS THE VIWE</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  
  &lt;html lang="en"&gt;
  &lt;head&gt;
      &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8"&gt; 
      &lt;title&gt;Sign Up!&lt;/title&gt;
      &lt;link rel="stylesheet" href="&lt;?php echo base_url();?&gt;css/style2.css" type="text/css" media="screen" /&gt;
  
  &lt;script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js" type="text/javascript" charset="utf-8"&gt;
  
  &lt;/script&gt;
  
  &lt;/head&gt;
  &lt;body&gt;
  &lt;?php $this-&gt;load-&gt;view('Includes/Header'); ?&gt;
  
  &lt;div id="main_content"&gt;
  
  &lt;?php $this-&gt;load-&gt;view($Main_content); ?&gt;
  
  &lt;/div&gt;
  
  &lt;?php //$this-&gt;load-&gt;view('includes/tut_info'); ?&gt;
  
  &lt;?php $this-&gt;load-&gt;view('Includes/Footer'); ?&gt;
  
      &lt;script type="text/javascript" charset="utf-8"&gt;
      $('input').click(function(){
          $(this).select();   
      });
  &lt;/script&gt;
  </code></pre>
  
  <p>
  </p>