aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFilipp Lepalaan <filipp@mekanisti.fi>2009-11-05 21:43:06 +0200
committerFilipp Lepalaan <filipp@mekanisti.fi>2009-11-05 21:43:06 +0200
commitf0bb7133827d4e36067333f70ba046e08cd53cd9 (patch)
treef7e695d80aec3c3b50201e1fb267c26260e42d52
parent6b75706de7a895967842ef3a6ed4af8c42be5ec7 (diff)
downloadmain-f0bb7133827d4e36067333f70ba046e08cd53cd9.tar.gz
main-f0bb7133827d4e36067333f70ba046e08cd53cd9.tar.bz2
main-f0bb7133827d4e36067333f70ba046e08cd53cd9.zip
Added HTTP auth
-rw-r--r--App.php19
1 files changed, 19 insertions, 0 deletions
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)
{