title: PHP if logic returns one result on first run and different results on all subsequent runs
body: <p>I'm having a little issue with some php logic in my main index page, that will include certain pages based on the results of some functions, mainly to do with login/logout and the first time a user logs in after registering. The php that manages the includes is below:</p>
  
  <p>UPDATE: (Based on suggestions from @arjan and @bigman I've updated the code as follows. The end result is still the same).</p>
  
  <pre><code>&lt;?php
  if ($login-&gt;checkForRegisterPage()) {
      include("views/pages/home.php");
  // are we logged in ?
  } elseif ($login-&gt;isLoggedIn()) {
  
      // check whether account is activated
      if (!$login-&gt;checkActivated()) {
          include("views/pages/activate.php");
  
      // check whether user has logged in before
      } elseif ($login-&gt;checkFirstLogin()) {
          include("views/pages/build_profile.php");
  
      // check action in URL and redirect accordingly
      } elseif ($checkaction-&gt;checkForBuildProfilePage()) {
          include("views/pages/build_profile.php");
      } elseif ($checkaction-&gt;checkForViewProfilePage()) {
          include("views/pages/profile.php");
  
      // if all else fails, load the dashboard
      } else {
          include("views/pages/dashboard.php");
      }
  } else {
  
      // not logged in, showing the login form
      include("views/pages/home.php");
  }
  ?&gt;
  </code></pre>
  
  <p>The problem is with the two functions $login->checkActivated(); and $login->checkFirstLogin(); included below:</p>
  
  <pre><code>public function checkFirstLogin() {
    $checkfirstlogin = $this-&gt;db-&gt;query("SELECT first_login FROM users WHERE first_login = 'Y' AND user_name = '".$this-&gt;user_name."';");
  
    if($checkfirstlogin-&gt;num_rows == 1) {
      return true;
    } else {
      return false;
    }
  }
  
  
  public function checkActivated() {
    $checkactivated = $this-&gt;db-&gt;query("SELECT activated FROM users WHERE activated = 'N' AND user_name = '".$this-&gt;user_name."';");
  
    if($checkactivated-&gt;num_rows == 1) {
      return false;
    } else {
      return true;
    }
  }
  </code></pre>
  
  <p>When the user first logs in, these functions return the correct result and I receive the page that I want. However, after login, I can still click and travel to other links on the page e.g. <code>checkForViewProfilePage();</code> looks for view=profile in the URL. The thing is in order for the logic to reach the point where it even checks for that, it would have had to get past the two functions <code>checkActivate();</code> and <code>checkFirstLogin();</code>, which it shouldn't be able to do while those criteria are met, but it still can. I hope I'm making sense. Can anyone see an error?</p>
  
  <p>Obviously my login form calls the Login class which the awkward functions are stored in, and so this would be loaded on login, but the class is included in the same way here so I'm not sure why the functions don't appear to be firing.</p>