1 |
13614
|
aaronmk
|
<?php
|
2 |
13694
|
aaronmk
|
function login__from_env()
|
3 |
|
|
{
|
4 |
|
|
return $_SERVER["PHP_AUTH_USER"]
|
5 |
|
|
.($_SERVER["PHP_AUTH_PW"] !== "" ? ":".$_SERVER["PHP_AUTH_PW"] : "");
|
6 |
|
|
}
|
7 |
|
|
|
8 |
13614
|
aaronmk
|
function user2path($user) # multiple @ and nested . OK: a@b.c@url -> url?b.c.a
|
9 |
|
|
{ return implode(".", array_reverse(explode("@", $user))); }
|
10 |
|
|
|
11 |
|
|
if (!isset($_SERVER["PHP_AUTH_USER"])) # browser first omits Authorization
|
12 |
|
|
{
|
13 |
|
|
header('WWW-Authenticate: Basic realm="please leave username/password blank or as filled in"');
|
14 |
|
|
}
|
15 |
|
|
else
|
16 |
|
|
{
|
17 |
13668
|
aaronmk
|
$dest = preg_replace('!\b/!', "./", $_SERVER["SCRIPT_URI"])."?";
|
18 |
|
|
# append trailing . to host to prevent infinite redirect loop
|
19 |
13665
|
aaronmk
|
if ($_SERVER["PHP_AUTH_USER"] !== "") # prepend to query string
|
20 |
13694
|
aaronmk
|
$dest .= "."/*force dotpath*/.user2path(login__from_env());
|
21 |
13665
|
aaronmk
|
$dest .= $_SERVER["QUERY_STRING"];
|
22 |
13625
|
aaronmk
|
|
23 |
|
|
header("Location: ".$dest);
|
24 |
13614
|
aaronmk
|
}
|
25 |
|
|
?>
|