1
0

http-auth.php 1.0 KB

1234567891011121314151617181920212223242526272829303132333435
  1. <?php
  2. /**
  3. * dolphin. Collection of useful PHP skeletons.
  4. * Copyright (C) 2017 Johannes 'Banana' Keßler
  5. *
  6. * This program is free software: you can redistribute it and/or modify
  7. * it under the terms of the COMMON DEVELOPMENT AND DISTRIBUTION LICENSE
  8. *
  9. * You should have received a copy of the
  10. * COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0
  11. * along with this program. If not, see http://www.sun.com/cddl/cddl.html
  12. */
  13. /**
  14. * simple HTTP auth method with PHP
  15. * more details can be found here:
  16. * http://php.net/manual/en/features.http-auth.php
  17. */
  18. # place this anywhere you need it.
  19. # define FRONTEND_USERNAME and FRONTEND_PASSWORD as a constand
  20. simpleAuth();
  21. function simpleAuth() {
  22. if (!isset($_SERVER['PHP_AUTH_USER']) || !isset($_SERVER['PHP_AUTH_PW'])
  23. || $_SERVER['PHP_AUTH_USER'] !== FRONTEND_USERNAME || $_SERVER['PHP_AUTH_PW'] !== FRONTEND_PASSWORD
  24. ) {
  25. header('WWW-Authenticate: Basic realm="Your secret area"');
  26. header('HTTP/1.0 401 Unauthorized');
  27. echo 'No Access.';
  28. exit;
  29. }
  30. }
  31. ?>