问题
I have this script snippet:
$headers = apache_request_headers();
if (!isset($headers['Authorization'])){
header('HTTP/1.1 401 Unauthorized');
header('WWW-Authenticate: NTLM');
//header("location: login.php");
exit;
}
$auth = $headers['Authorization'];
if (substr($auth,0,5) == 'NTLM ') {
$msg = base64_decode(substr($auth, 5));
if (substr($msg, 0, 8) != "NTLMSSP\x00")
die(header('location: login.php'));
if ($msg[8] == "\x01") {
$msg2 = "NTLMSSP\x00\x02"."\x00\x00\x00\x00". // target name len/alloc
"\x00\x00\x00\x00". // target name offset
"\x01\x02\x81\x01". // flags
"\x00\x00\x00\x00\x00\x00\x00\x00". // challenge
"\x00\x00\x00\x00\x00\x00\x00\x00". // context
"\x00\x00\x00\x00\x30\x00\x00\x00"; // target info len/alloc/offset
header('HTTP/1.1 401 Unauthorized');
header('WWW-Authenticate: NTLM '.trim(base64_encode($msg2)));
exit;
}
else if ($msg[8] == "\x03") {
function get_msg_str($msg, $start, $unicode = true) {
$len = (ord($msg[$start+1]) * 256) + ord($msg[$start]);
$off = (ord($msg[$start+5]) * 256) + ord($msg[$start+4]);
if ($unicode)
return str_replace("\0", '', substr($msg, $off, $len));
else
return substr($msg, $off, $len);
}
$user = get_msg_str($msg, 36);
$domain = get_msg_str($msg, 28);
$workstation = get_msg_str($msg, 44);
$user = preg_replace('/[^0-9]/','',$user);
All I want to do is redirect the browser to login.php if the NTLM feature wont work.
You can see by the line I commented out what I tried, and I had tried a few others... But everything so far seems to redirect everyone, even the browsers capable of NTLM..
Thanks!
EDIT 1
I should add that I dont want the browsers who dont support NTLM to prompt for credentials as there is already a page made for that.
来源:https://stackoverflow.com/questions/34141236/how-to-redirect-if-ntlm-authentication-wont-work