用PHP获得windows登录用户名的方法
时间:2007-05-22
来源:互联网
所以赶快拿出来与大家分享.这是一个法国人写的,所以编码中的注释都是法语,如果有朋友很想了解某行的注释含义,请回帖说明,我可以试着翻译一下.
PHP代码:
<?php
/***********************************************************************
************************************************************************
*
* PHP NTLM GET LOGIN
* Version 0.2.1
* [url=http://www.secusquad.com/ntlm/]http://www.secusquad.com/ntlm/[/url]
* Copyright (c) 2004 Nicolas GOLLET ( Nicolas (dot) gollet (at) secusquad (dot) com )
* Copyright (c) 2004 Flextronics Saint-Etienne
*
* This program is free software. You can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License.
*
***********************************************************************/
session_start();
$headers = apache_request_headers(); // 获取用户头
if (@$_SERVER['HTTP_VIA'] != NULL){ // 确认是否使用了代理(proxy),因为ntlm验证不能穿过代理.
echo "Proxy bypass!";
}
elseif($headers['Authorization'] == NULL){ //si l'entete autorisation est inexistante如果许可头不存在
header( "HTTP/1.0 401 Unauthorized" ); //envoi au client le mode d'identification
header( "WWW-Authenticate: NTLM" ); //dans notre cas le NTLM
exit; //on quitte
}
if(isset($headers['Authorization'])) //dans le cas d'une authorisation (identification)
{
if(substr($headers['Authorization'],0,5) == 'NTLM '){ // 确认client是否在ntlm下
$chaine=$headers['Authorization'];
$chaine=substr($chaine, 5); // 获取 base64-encoded type1 信息
$chained64=base64_decode($chaine); // 解码 base64 到 $chained64
if(ord($chained64{8}) == 1){
// |_ byte signifiant l'etape du processus d'identification (etape 3)
// verification du drapeau NTLM "0xb2" ?l'offset 13 dans le message type-1-message (comp ie 5.5+) :
if (ord($chained64[13]) != 178){
echo "NTLM Flag error!";
exit;
}
$retAuth = "NTLMSSP".chr(000).chr(002).chr(000).chr(000).chr(000).chr(000).chr(000).chr(000);
$retAuth .= chr(000).chr(040).chr(000).chr(000).chr(000).chr(001).chr(130).chr(000).chr(000);
$retAuth .= chr(000).chr(002).chr(002).chr(002).chr(000).chr(000).chr(000).chr(000).chr(000);
$retAuth .= chr(000).chr(000).chr(000).chr(000).chr(000).chr(000).chr(000);
$retAuth64 =base64_encode($retAuth); // encode en base64
$retAuth64 = trim($retAuth64); // enleve les espaces de debut et de fin
header( "HTTP/1.0 401 Unauthorized" ); // envoi le nouveau header
header( "WWW-Authenticate: NTLM $retAuth64" ); // avec l'identification suppl�mentaire
exit;
}
else if(ord($chained64{8}) == 3){
// |_ byte signifiant l'etape du processus d'identification (etape 5)
// on recupere le domaine
$lenght_domain = (ord($chained64[31])*256 + ord($chained64[30])); // longueur du domain
$offset_domain = (ord($chained64[33])*256 + ord($chained64[32])); // position du domain.
$domain = str_replace("\0","",substr($chained64, $offset_domain, $lenght_domain)); // decoupage du du domain
//le login
$lenght_login = (ord($chained64[39])*256 + ord($chained64[38])); // longueur du login.
$offset_login = (ord($chained64[41])*256 + ord($chained64[40])); // position du login.
$login = str_replace("\0","",substr($chained64, $offset_login, $lenght_login)); // decoupage du login
if ( $login != NULL){
// stockage des donn�es dans des variable de session
$_SESSION['Login']=$login;
header("Location: newpage.php");
exit;
}
else{
echo "NT Login empty!";
}
}
}
}
?>
作者: paperassword 发布时间: 2007-05-21
作者: softly 发布时间: 2007-05-21
作者: heixiake 发布时间: 2007-05-21
作者: 木�^ 发布时间: 2007-05-21
作者: yiqieqie 发布时间: 2007-05-23
引用:
原帖由 yiqieqie 于 2007-5-23 19:32 发表如何测试使用呢?
把整段程序放到一个php文件中,
修改下面一段
if ( $login != NULL){
$_SESSION['Login']=$login;
header("Location: newpage.php");
exit;
}
为
if ( $login != NULL){
$_SESSION['Login']=$login;
echo $login;
exit;
}
然后运行这个文件,就可以看到windows的用户名显示出来了.
[ 本帖最后由 paperassword 于 2007-5-23 20:04 编辑 ]
作者: paperassword 发布时间: 2007-05-23
作者: cator 发布时间: 2007-05-23
作者: 风中漫步 发布时间: 2007-05-24
作者: xiaoqiang527 发布时间: 2007-05-24
作者: syxrrrr 发布时间: 2007-05-24
作者: scanh 发布时间: 2007-05-25
作者: skyjhz 发布时间: 2007-05-25
引用:
原帖由 scanh 于 2007-5-25 17:19 发表那就麻烦法语大侠翻译一下,有很多地方都不冷理解。
作者: paperassword 发布时间: 2007-05-31
寻找真正能够得到WINDOWS登录用户名的方法…………
作者: 11X22S33 发布时间: 2008-02-29


作者: fjch1986 发布时间: 2008-02-29
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28