diff options
author | Filipp Lepalaan <filipp@mekanisti.fi> | 2009-11-05 21:43:06 +0200 |
---|---|---|
committer | Filipp Lepalaan <filipp@mekanisti.fi> | 2009-11-05 21:43:06 +0200 |
commit | f0bb7133827d4e36067333f70ba046e08cd53cd9 (patch) | |
tree | f7e695d80aec3c3b50201e1fb267c26260e42d52 | |
parent | 6b75706de7a895967842ef3a6ed4af8c42be5ec7 (diff) | |
download | main-f0bb7133827d4e36067333f70ba046e08cd53cd9.tar.gz main-f0bb7133827d4e36067333f70ba046e08cd53cd9.tar.bz2 main-f0bb7133827d4e36067333f70ba046e08cd53cd9.zip |
Added HTTP auth
-rw-r--r-- | App.php | 19 |
1 files changed, 19 insertions, 0 deletions
@@ -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) { |