title: PHP session destroy Trying to destroy uninitialized session
body: <p>I've read several topics like: </p>
  
  <p><a href="https://stackoverflow.com/questions/18551030/error-session-destroy-trying-to-destroy-uninitialized-session">Error — session_destroy() — Trying to destroy uninitialized session</a>, <a href="https://stackoverflow.com/questions/18188716/warning-session-destroy-trying-to-destroy-uninitialized-session">Warning: session_destroy(): Trying to destroy uninitialized session</a>, <a href="https://stackoverflow.com/questions/17522574/warning-session-destroy-trying-to-destroy-uninitialized-session-with-phpcas">Warning: session_destroy(): Trying to destroy uninitialized session with phpCas</a></p>
  
  <p>And none of them help me.</p>
  
  <pre><code>public function forbidden(){
      if(!isset($_SESSION)){ session_start(); }
  
      if(!isset($_SESSION['email']) || !isset($_SESSION['id'])){
          $this-&gt;error_404();
      }else{
  
          if(!isset($_COOKIE['data'])){
              session_destroy();
              $this-&gt;error_404();
          }
  
          if($_COOKIE['data'] != sha1($_SESSION['email'])){
              session_destroy();
              unset($_COOKIE["data"]);
              setcookie("data", false, time() - 3600, '/');
              $this-&gt;error_404();
          }
      }
  }
  </code></pre>
  
  <blockquote>
    <p>Warning: session_destroy() [function.session-destroy]: Trying to
    destroy uninitialized session</p>
  </blockquote>
  
  <p>I do receive that error on the second <code>session_destroy();</code>, the session is initialized so I don't get it?</p>