title: PHP session validation
body: <p>I want to write a script that can only be accessed by an administrator. </p>
  
  <p>This is how I want to do it:</p>
  
  <pre><code>session_start();
  
  if (!isset($_SESSION['user_id'])) { //not logged in
  
      //redirect to homepage
      header("Location: http://domain.com/index.php");
      die();
  
  }
  
  if ($_SESSION['user_level'] != 1337) { //not admin
  
      //redirect to homepage
      header("Location: http://domain.com/index.php");
      die();
  
  }
  
  if ($_SERVER['REQUEST_METHOD'] == 'POST') { //form is submitted
  
      //validate the submitted data
      //submit the query
  
  }
  
  //form goes here
  </code></pre>
  
  <p>My question is: Is there a better way of validating this (eg. should all three conditionals be nested) or is this enough?</p>
  
  <p>Cheers,</p>
  
  <p>n1te</p>