Posted By

smokestack on 05/22/09


Tagged

http authentication symfony


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

smokestack


Add HTTP authentication to an application with filter


 / Published in: PHP
 

URL: http://www.refactory.org/s/add_http_authentication_to_an_application_with_filter/view/latest

From refactory.org

httpAuthFilter adds single-user application-wide HTTP authentication.

  1. <?php
  2.  
  3. class httpAuthFilter extends sfFilter
  4. {
  5.  
  6. public function execute($filterChain)
  7. {
  8. if($this->isFirstCall()) {
  9. if(!isset($_SERVER['PHP_AUTH_USER']) or
  10. ($_SERVER['PHP_AUTH_USER'] == sfConfig::get('app_auth_username') && $_SERVER['PHP_AUTH_PW'] == sfConfig::get('app_auth_password')) == false) {
  11.  
  12. $this->sendHttpAuthHeaders();
  13. }
  14. }
  15.  
  16. $filterChain->execute();
  17. }
  18.  
  19. public function sendHttpAuthHeaders()
  20. {
  21. header('WWW-Authenticate: Basic realm="' . sfConfig::get('app_auth_realm') . '"');
  22. header('HTTP/1.0 401 Unauthorized');
  23. exit();
  24. }
  25.  
  26. }

Report this snippet  

You need to login to post a comment.