title: Restricted pages - Only visible to logged in users - PHP
body: <p>I have Login &amp; Register system with the protected page ( home page ). When users create an account and log in with a username and password, the system will redirect the user to the home page. On the home page, I have a code for restriction ( only logged in users can be on the home page ):</p>
  <pre><code>session_start();
  session_destroy();
  
  include $_SERVER['DOCUMENT_ROOT'] . '/web/route.php';
  include $_SERVER['DOCUMENT_ROOT'] . '/app/database/config.php';
  include $_SERVER['DOCUMENT_ROOT'] . '/app/functions/navigation.php';
  
  if (!isset($_SESSION['username'])) {
      header('location: ../');
      exit();
  }
  </code></pre>
  <p>And if I try to open that page if I am not logged in, the system will automatically redirect me back to the login page. Now I create the second page ( contact support ) and copy the same code to a new page, I don't get any error's but I only have redirection to the home page and when I try to open a manual new page, the system redirects me again and I am logged in. My logout code is:</p>
  <pre><code>session_start();
  session_destroy();
  
  if (isset($_COOKIE['authenticationSystem'])) {
  
      unset($_COOKIE['authenticationSystem']);
      setcookie('authenticationSystem', null, -1, '/');
  }
  
  header('location: index');
  </code></pre>
  <p>And if I add new code to a new page:</p>
  <pre><code>if (isset($_COOKIE['authenticationSystem'])) {
      header('location: ../');
      exit();
  }
  </code></pre>
  <p>I resolve the problem but I can't get user logged-in information. Can someone explain to me where is the problem, if any other information needs I will provide it?</p>
  <p>Thanks all</p>