title: PHP Login header location
body: <p>I have the following code, but im blocked here..</p>
  
  <pre><code>&lt;?php
  require 'members/core/init.php';
  $general-&gt;logged_in_protect();
  
  if (empty($_POST) === false) {
  
  $username = trim($_POST['username']);
  $password = trim($_POST['password']);
  
  if (empty($username) === true || empty($password) === true) {
      $errors[] = 'Sorry, but we need your username and password.';
  } else if ($users-&gt;user_exists($username) === false) {
      $errors[] = 'Sorry that username doesn\'t exists.';
  } else if ($users-&gt;email_confirmed($username) === false) {
      $errors[] = 'Sorry, but you need to activate your account. 
                   Please check your email.';
  } else {
      if (strlen($password) &gt; 18) {
          $errors[] = 'The password should be less than 18 characters, without spacing.';
      }
      $login = $users-&gt;login($username, $password);
      if ($login === false) {
          $errors[] = 'Sorry, that username/password is invalid';
      }else {
          session_regenerate_id(true);// destroying the old session id and creating a new one
          $_SESSION['id'] =  $login;
          header('Location: http://www.site.ro/1/index.html');
          exit();
      }
  }
  } 
  ?&gt;
  </code></pre>
  
  <p>and the following:</p>
  
  <pre><code>&lt;?php if ($page == 'login'): ?&gt;
  &lt;?php endif; ?&gt;
  </code></pre>
  
  <p>Can someone help me to combine that part of code?</p>
  
  <p>I've tryed that, but tell me header already send..</p>
  
  <pre><code>&lt;?php if ($page == 'login'): ?&gt;
  &lt;?php
  require 'members/core/init.php';
  $general-&gt;logged_in_protect();
  
  if (empty($_POST) === false) {
  
  $username = trim($_POST['username']);
  $password = trim($_POST['password']);
  
  if (empty($username) === true || empty($password) === true) {
      $errors[] = 'Sorry, but we need your username and password.';
  } else if ($users-&gt;user_exists($username) === false) {
      $errors[] = 'Sorry that username doesn\'t exists.';
  } else if ($users-&gt;email_confirmed($username) === false) {
      $errors[] = 'Sorry, but you need to activate your account. 
                   Please check your email.';
  } else {
      if (strlen($password) &gt; 18) {
          $errors[] = 'The password should be less than 18 characters, without spacing.';
      }
      $login = $users-&gt;login($username, $password);
      if ($login === false) {
          $errors[] = 'Sorry, that username/password is invalid';
      }else {
          session_regenerate_id(true);// destroying the old session id and creating a new one
          $_SESSION['id'] =  $login;
          header('Location: http://www.site.ro/1/index.html');
          exit();
      }
  }
  } 
  ?&gt;
  &lt;?php endif; ?&gt;
  </code></pre>
  
  <p>Im beginner in php, so please understand me.
  Thank you in advance.</p>
  
  <p>Resolved !</p>
  
  <p>That it's the final code:</p>
  
  <pre><code>&lt;?php if ($page == 'login'):
  require 'members/core/init.php';
  $general-&gt;logged_in_protect();
  
  if (empty($_POST) === false) {
  
  $username = trim($_POST['username']);
  $password = trim($_POST['password']);
  
  if (empty($username) === true || empty($password) === true) {
      $errors[] = 'Sorry, but we need your username and password.';
  } else if ($users-&gt;user_exists($username) === false) {
      $errors[] = 'Sorry that username doesn\'t exists.';
  } else if ($users-&gt;email_confirmed($username) === false) {
      $errors[] = 'Sorry, but you need to activate your account. 
                   Please check your email.';
  } else {
      if (strlen($password) &gt; 18) {
          $errors[] = 'The password should be less than 18 characters, without spacing.';
      }
      $login = $users-&gt;login($username, $password);
      if ($login === false) {
          $errors[] = 'Sorry, that username/password is invalid';
      }else {
          session_regenerate_id(true);// destroying the old session id and creating a new one
          $_SESSION['id'] =  $login;
          header('Location: http://www.site.ro/1/index.html');
          exit();
      }
  }
  } 
  endif; ?&gt;
  </code></pre>