Guest User

Untitled

a guest
Feb 1st, 2018
33
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.94 KB | None | 0 0
  1. <?php
  2. include_once('_users.php');
  3.  
  4. // Set connected flag to false
  5. $connected = false;
  6. $form_sent = false;
  7. // Check if POST data was send
  8. if(isset($_POST['username']) && isset($_POST['pass'])) {
  9.   $form_sent = true;
  10.  
  11.   $username = $_POST['username'];
  12.   $password = $_POST['pass'];
  13.  
  14.   // Check if username exists in db and if passwords match
  15.   if(isset($users[$username]) && $users[$username] == $password) {
  16.     // If password match, set flag to true
  17.     $connected = true;
  18.   }
  19. }
  20. ?>
  21.  
  22. <pre style="padding:10px; background: #eee"><?php var_dump($_POST); ?></pre>
  23.  
  24. <?php if(!$connected && $form_sent): ?>
  25. <p><b style="color:red">Wrong password or username</b></p>
  26. <?php endif; ?>
  27.  
  28. <?php if($connected): ?>
  29. <div><b>You are connected</b></div>
  30. <?php endif; ?>
  31.  
  32. <form method="POST">
  33.   <input type="text" name="username" required/>
  34.   <input type="password" name="pass" required/>
  35.   <input type="submit" value="Validate"/>
  36. </form>
Add Comment
Please, Sign In to add comment