title: How to use the Observer pattern in PHP login system?
body: <p>I am new at design patterns. And I have a log-in system with classes to connect to my database and stuff like that.</p>
  
  <p>But now I want to include a observer pattern in my PHP code. But I don't know how do to that. For example a user I notified whenever there is a new user. I know how the observer pattern works, what it does for example. But I don't know how to include it to PHP code. So how do you do a login system that includes observer pattern?</p>
  
  <p>For example here is my connection class to my database:</p>
  
  <pre><code>private $pdo;
  
  function __construct() {
      $this-&gt;pdo = new PDO('mysql:host=localhost;dbname=users', '', '');
  }
  </code></pre>
  
  <p>And heres is the code i using in the login file:</p>
  
  <pre><code>if(isset($_POST['username']) &amp;&amp; isset($_POST['password'])) {
      include_once("classes/database.php");
      $db = new DB();
      $result = $db-&gt;query("SELECT username, pass FROM users WHERE username='".$_POST['username']."' AND pass='".$_POST['password']."'");
  
      if(isset($result[0]['username']) &amp;&amp; isset($result[0]['password'])) {
          $_SESSION['username'] = $_POST['username'];
          header("Location: start.php?username=".$_SESSION['username']);
      }
  </code></pre>