title: PHP Check if user is logged in with a function
body: <p>I'm working on a website and the index page checks if the user is logged in or not with this piece of code:</p>
  
  <pre><code>if (!$_SESSION['login'] &amp;&amp; $_SESSION['login'] == "") {
  include_once($_SERVER['DOCUMENT_ROOT'] . "/login/");
  } elseif ($_SESSION['login'] == 1) {
  include_once($_SERVER['DOCUMENT_ROOT'] . "/main/");
  }
  </code></pre>
  
  <p>But I want it to look cleaner, then I started wondering if was possible to achieve something like this with a function:</p>
  
  <pre><code>checklogin($_SESSION['login']);
  </code></pre>
  
  <p>I don't have much experience with functions, so i'm sorry if my question looks stupid, so thanks in advance.</p>