From f0bb7133827d4e36067333f70ba046e08cd53cd9 Mon Sep 17 00:00:00 2001 From: Filipp Lepalaan Date: Thu, 5 Nov 2009 21:43:06 +0200 Subject: Added HTTP auth --- App.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/App.php b/App.php index 242d2bb..963396d 100644 --- a/App.php +++ b/App.php @@ -263,6 +263,25 @@ class App return $out; } + + /** + * Prompt for HTTP authentication + * @param string [$callback] Function that makes the actual authentication + * @param string [$realm] Realm name + * @return mixed false if cancelled or output of $function + */ + static function auth($callback, $realm = "Default") + { + if (!isset($_SERVER['PHP_AUTH_USER'])) + { + $header = sprintf('WWW-Authenticate: Basic realm="%s"', $realm) + header($header); + header("HTTP/1.0 401 Unauthorized"); + return false; + } else { + return call_user_func($callback, $_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']); + } + } public function js($string) { -- cgit v1.2.3