aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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)
{