4 http user space authentication
5 ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
6 can be used with the tools/, if you don't want to fiddle
7 with the .htaccess and .htpasswd files for your webserver
11 #-- (pw array - I have such one in an external config file)
12 $passwords = (array)$passwords + array(
13 // "user" => "password",
14 // "u2" => "password",
16 if (defined("EWIKI_ADMIN_PW")) {
17 $passwords["admin"] = EWIKI_ADMIN_PW;
19 if (empty($passwords)) {
20 die("<h1>Restricted Access</h1>\nPlease first create an admin account in '<tt>.../fragments/funcs/auth.php</tt>' or define() the '<tt>EWIKI_ADMIN_PW</tt>' constant.");
24 #-- fetch user:password
25 if ($uu = $_SERVER["HTTP_AUTHORIZATION"]) {
26 foreach (explode(",", $uu) as $uu) {
28 if (strtoupper(strtok($uu, " ")) == "BASIC") {
30 $uu = base64_decode($uu);
31 list($_a_user, $_a_password) = explode(":", $uu, 2);
35 elseif (strlen($_a_user = trim($_SERVER["PHP_AUTH_USER"]))) {
36 $_a_password = trim($_SERVER["PHP_AUTH_PW"]);
41 if ($_a_user && $_a_password && ($_a_password==@$passwords[$_a_user])) {
45 #-- request HTTP Basic authentication otherwise
47 header('HTTP/1.1 401 Authentication Required');
48 header('Status: 401 Authentication Required');
49 header('WWW-Authenticate: Basic realm="restricted access"');