我有这个脚本片段:
$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);
如果NTLM功能不起作用,我想要做的就是将浏览器重定向到login.php。
你可以通过这条线看到我评论了我尝试过的东西,并且我尝试了其他一些......但到目前为止,所有内容似乎都重定向了所有人,甚至是能够使用NTLM的浏览器..
谢谢!
编辑1
我应该补充一点,我不希望那些不支持NTLM的浏览器提示输入凭据,因为已经有一个页面。