title: Design pattern for an authentication system in PHP
body: <p>I'm learning PHP, and I'm curious if there are elegant solutions to designing an authentication interface for a website.</p>
  
  <p>Basically, I will have three types of users: Regular Users, Admins, and "Power users".
  each type of user will have its own actions.</p>
  
  <p>Here is a brief sketch of my current code:</p>
  
  <pre><code># Regular User = Non-Authenticated
  interface IRegularUser {
          # Will return an object of a class that implements this interface
          public static function loginUser ($name, $pass);
  }
  
  # Authenticated User
  class AuthUser extends RegularUser {
          public function logoutUser();
  }
  
  interface IAdmin {..}
  interface IPowerUser {...}
  class User implements IRegularUser {}
  class Admin     extends AuthUser implements IAdmin {}
  class PowerUser extends AuthUser implements IPowerUser {}
  </code></pre>
  
  <p>In the script that checks for correct login, I would write something similar to this:</p>
  
  <pre><code>$user = new User();
  $user = $user-&gt;loginUser($_POST['username'], $_POST['password']);
  
  if (get_class($user) == get_class(new Admin()))
      # Redirect to admin_home.html   
  else if (get_class($user) == get_class(new PowerUser()))
      # Redirect to power_user_home.html
  </code></pre>
  
  <p>I am trying to use the OOP features of PHP, in order to establish some constraints between the entities in my application (Ex: Only by acquiring an User object, you can then login, and acquire an object of type Admin, or PowerUser).</p>
  
  <p>I feel that my authentication system is kind of clunky, and I would like to know if there is a common design pattern for a webapp authentication system.</p>