PHP获取windows登录用户名的方法
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了PHP获取windows登录用户名的方法,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含3209字,纯文字阅读大概需要5分钟。
内容图文
此方法依赖 Apache 和 NTLM
<?php /*********************************************************************** ************************************************************************ * * PHP NTLM GET LOGIN * Version 0.2.1 * 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‘identificationheader( "WWW-Authenticate: NTLM" ); //dans notre cas le NTLMexit; //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 到 $chained64if(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 finheader( "HTTP/1.0 401 Unauthorized" ); // envoi le nouveau headerheader( "WWW-Authenticate: NTLM $retAuth64" ); // avec l‘identification suppl?entaireexit; } elseif(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 loginif ( $login != NULL){ // stockage des donn?s dans des variable de session$_SESSION[‘Login‘]=$login; header("Location: newpage.php"); exit; } else{ echo "NT Login empty!"; } } } } ?>
原文:http://www.cnblogs.com/ckcai/p/5144473.html
内容总结
以上是互联网集市为您收集整理的PHP获取windows登录用户名的方法全部内容,希望文章能够帮你解决PHP获取windows登录用户名的方法所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。