1 |
13614
|
aaronmk
|
<?php
|
2 |
|
|
function user2path($user) # multiple @ and nested . OK: a@b.c@url -> url?b.c.a
|
3 |
|
|
{ return implode(".", array_reverse(explode("@", $user))); }
|
4 |
|
|
|
5 |
|
|
if (!isset($_SERVER["PHP_AUTH_USER"])) # browser first omits Authorization
|
6 |
|
|
{
|
7 |
|
|
header('WWW-Authenticate: Basic realm="please leave username/password blank or as filled in"');
|
8 |
|
|
}
|
9 |
|
|
else
|
10 |
|
|
{
|
11 |
13617
|
aaronmk
|
$subpath = user2path($_SERVER["PHP_AUTH_USER"]);
|
12 |
13614
|
aaronmk
|
header("Location: ".($_SERVER["PHP_AUTH_USER"] !== ""
|
13 |
13617
|
aaronmk
|
? ($_SERVER["QUERY_STRING"] !== ""
|
14 |
|
|
? /*prepend to query string*/$_SERVER["SCRIPT_URL"]
|
15 |
13622
|
aaronmk
|
."?.".$subpath.ltrim($_SERVER["QUERY_STRING"], "@")
|
16 |
13617
|
aaronmk
|
: $_SERVER["REQUEST_URI"]/*ends in ? */.$subpath
|
17 |
|
|
)
|
18 |
|
|
: rtrim($_SERVER["REQUEST_URI"], "?") #user empty->just display page
|
19 |
13614
|
aaronmk
|
));
|
20 |
|
|
}
|
21 |
|
|
?>
|