Created
August 16, 2011 08:59
-
-
Save umpirsky/1148691 to your computer and use it in GitHub Desktop.
Simple Zend Framework admin controller secured by basic HTTP authentication
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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