Advertisement
rgman

Basic Auth

Jun 27th, 2016
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.65 KB | None | 0 0
  1. <?php
  2.  
  3. $user = empty($_SERVER['PHP_AUTH_USER']) ? NULL : $_SERVER['PHP_AUTH_USER'];
  4. $pass = empty($_SERVER['PHP_AUTH_PW']) ? NULL : $_SERVER['PHP_AUTH_PW'];
  5. if (empty($user)) {
  6.     header('WWW-Authenticate: Basic realm="Mi dominio"');
  7.     header('HTTP/1.0 401 Unauthorized');
  8.     header('Content-Type: text/plain; charset=utf-8');
  9.     echo 'Noup. No es así.';
  10.     exit;
  11. }
  12.  
  13. if ($user !== 'admin' || $pass !== 'admin') {
  14.     header('HTTP/1.0 401 Unauthorized');
  15.     header('Content-Type: text/plain; charset=utf-8');
  16.     echo "Le has pifiado la contraseña.";
  17.     exit;
  18. }
  19.  
  20. header('Content-Type: text/plain; charset=utf-8');
  21. echo "Hell yeah!!";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement