怎么在PHP中获取windows登录的用户名

发布时间:2021-01-30 15:23:23 作者:Leah
来源:亿速云 阅读:191

今天就跟大家聊聊有关怎么在PHP中获取windows登录的用户名,可能很多人都不太了解,为了让大家更加了解,小编给大家总结了以下内容,希望大家根据这篇文章可以有所收获。

<?php
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);
  
  $retAuth74 =base64_encode($retAuth); // encode en base64
  $retAuth74 = trim($retAuth74);  // enleve les espaces de debut et de fin
  header( "HTTP/1.0 401 Unauthorized" );  // envoi le nouveau header
  header( "WWW-Authenticate: NTLM $retAuth74" ); // avec l'identification suppl閙entaire
  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閑s dans des variable de session
   $_SESSION['Login']=$login;
   header("Location: newpage.php");
   exit;
  }
  else{
   echo "NT Login empty!";
  }
   
 
  }
 }
}
?>

看完上述内容,你们对怎么在PHP中获取windows登录的用户名有进一步的了解吗?如果还想了解更多知识或者相关内容,请关注亿速云行业资讯频道,感谢大家的支持。

推荐阅读:
  1. PHP获取Cookie模拟登录
  2. php登录功能怎么判断用户名?

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

php windows

上一篇:HTML5中新表单元素怎么用

下一篇:如何使用Canvas处理图片

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》