title: session_start() [function.session-start]: Cannot send session cookie - headers already sent
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/8028957/headers-already-sent-by-php">Headers already sent by PHP</a>  </p>
  </blockquote>
  
  
  
  <p>I am new in object-oriented PHP. This code works well in function php but it makes some error in OOP PHP.</p>
  
  <p>When i open index.php then error message as like as show below but all other code works well ::  </p>
  
  <pre><code>Warning: session_start() [function.session-start]: Cannot send session cookie - headers 
    already sent by (output started at 
    E:\XAMPP\xampp\htdocs\photo_gallery_new\public\layout\header.php:14) in 
    E:\XAMPP\xampp\htdocs\photo_gallery_new\Includes\session.php on line 15
  
    Warning: session_start() [function.session-start]: Cannot send session cache limiter -
     headers already sent (output started at 
    E:\XAMPP\xampp\htdocs\photo_gallery_new\public\layout\header.php:14) in
     E:\XAMPP\xampp\htdocs\photo_gallery_new\Includes\session.php on line 15
  </code></pre>
  
  <p>The code ::  </p>
  
  <p>index.php</p>
  
  <pre><code> &lt;?php  include ("../public/layout/header.php"); ?&gt; // for design   header
  &lt;h2&gt; Menu &lt;/h2&gt;
   &lt;?php
  
  require_once ("../Includes/initiate.php");   // it makes error 
  //require_once ("../Includes/user.php");    // it works 
  //require_once ("../Includes/database_object.php");  // it makes error      
  
  echo $user-&gt;full_name();
  echo "&lt;hr /&gt;";
    ?&gt;
  &lt;/div&gt;   
    &lt;?php  include ("../public/layout/footer.php");   ?&gt;  // design for footer
  </code></pre>
  
  <p>user.php</p>
  
  <pre><code>&lt;?php
  require_once ("database.php");
  
   class USER extends  databaseObject {  // it makes error
  //class USER {  // but it works         
       public $id; public $username; public $password;    public $firstName;
           public $lastName;
       // user authenticate   
       public static function authenticate( $username="", $password="" ) { ...  } 
  
       public function full_name()  {..... } // find full name
       // common database action
       public static function record_all_user() { ...  } // find all user
  
       public static function record_by_id($id=0) {.....} // find specific user
  
       public static function record_by_sql($sql="") { ...... }  // check sql
      ?&gt;
  </code></pre>
  
  <p>header.php</p>
  
  <pre><code> &lt;html&gt;
    &lt;head&gt;
   &lt;title&gt; Photo Gallery &lt;/title&gt;
  &lt;link href="stylesheet/main.css" media="all" rel="stylesheet" type="text/css" /&gt;
    &lt;/head&gt;
  &lt;body&gt;
     &lt;div id="header"&gt;
       &lt;h1&gt; PHOTO GALLERY &lt;/h1&gt;
     &lt;/div&gt;
  &lt;div id="main"&gt;
  </code></pre>
  
  <p>session.php</p>
  
  <pre><code>&lt;?php
     class Session {          
      private $logged_in = FALSE;
      public $user_id;            
      function  __construct()  {
          session_start();
          $this-&gt;check_login();           
            .............................
              }
  
      public function is_logged_in() {....} // check loged in  
  
      public function login($user) { .....  }
  
      public function logout() {
          unset($_SESSION['user_id']);
          unset($this-&gt;user_id);
          $this-&gt;logged_in = FALSE;
      }
  
      private function check_login()  {... .}  // check login
  }    
  
  $session = new Session();
   ?&gt; 
  </code></pre>
  
  <p>initiate.php</p>
  
  <pre><code> &lt;?php
    require_once ("Config.php");
  require_once ("Functions.php");
  require_once ("session.php");
  require_once ("Database.php");
  require_once ("database_object.php");  // this makes error
  require_once ("user.php");
   ?&gt;
  </code></pre>
  
  <p>database_object.php</p>
  
  <pre><code> &lt;?php
  require_once ("database.php");
     class databaseObject {
  
  }
  $newClass = new databaseObject();
    ?&gt;    
  </code></pre>