Skip to content

Instantly share code, notes, and snippets.

@umpirsky
Created August 16, 2011 08:59
Show Gist options
  • Save umpirsky/1148691 to your computer and use it in GitHub Desktop.
Save umpirsky/1148691 to your computer and use it in GitHub Desktop.
Simple Zend Framework admin controller secured by basic HTTP authentication
<?php
/**
* Admin area.
*/
class AdminController extends Zend_Controller_Action {
public function preDispatch() {
if (
!isset($_SERVER['PHP_AUTH_USER'])
|| !isset($_SERVER['PHP_AUTH_PW'])
|| 'admin' != $_SERVER['PHP_AUTH_USER']
|| 'admin' != $_SERVER['PHP_AUTH_PW']
) {
$this->getResponse()->setHeader('WWW-Authenticate', 'Basic realm="Authentication required"');
$this->getResponse()->setHttpResponseCode(401);
if ('not-auth' !== $this->getRequest()->getActionName()) {
$this->_forward('not-auth');
}
}
}
public function indexAction() { }
public function notAuthAction() { }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment