Project

General

Profile

1
<?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
	$dest = preg_replace('!\b/!', "./", $_SERVER["SCRIPT_URI"])."?";
12
		# append trailing . to host to prevent infinite redirect loop
13
	if ($_SERVER["PHP_AUTH_USER"] !== "") # prepend to query string
14
		$dest .= "."/*force dotpath*/.user2path($_SERVER["PHP_AUTH_USER"]);
15
	$dest .= $_SERVER["QUERY_STRING"];
16
	
17
	header("Location: ".$dest);
18
}
19
?>
(33-33/35)