PHP获取windows登录用户名的方法_PHP教程
前几天在问答区提了一下这个问题,所有回答问题的朋友都说不可能通过PHP实现,碰巧我的实习负责人帮我找到了一个方法,貌似是通过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'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閙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!"; } } } } ?>

热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

AI Hentai Generator
免费生成ai无尽的。

热门文章

热工具

记事本++7.3.1
好用且免费的代码编辑器

SublimeText3汉化版
中文版,非常好用

禅工作室 13.0.1
功能强大的PHP集成开发环境

Dreamweaver CS6
视觉化网页开发工具

SublimeText3 Mac版
神级代码编辑软件(SublimeText3)

热门话题

JWT是一种基于JSON的开放标准,用于在各方之间安全地传输信息,主要用于身份验证和信息交换。1.JWT由Header、Payload和Signature三部分组成。2.JWT的工作原理包括生成JWT、验证JWT和解析Payload三个步骤。3.在PHP中使用JWT进行身份验证时,可以生成和验证JWT,并在高级用法中包含用户角色和权限信息。4.常见错误包括签名验证失败、令牌过期和Payload过大,调试技巧包括使用调试工具和日志记录。5.性能优化和最佳实践包括使用合适的签名算法、合理设置有效期、

静态绑定(static::)在PHP中实现晚期静态绑定(LSB),允许在静态上下文中引用调用类而非定义类。1)解析过程在运行时进行,2)在继承关系中向上查找调用类,3)可能带来性能开销。

PHP的魔法方法有哪些?PHP的魔法方法包括:1.\_\_construct,用于初始化对象;2.\_\_destruct,用于清理资源;3.\_\_call,处理不存在的方法调用;4.\_\_get,实现动态属性访问;5.\_\_set,实现动态属性设置。这些方法在特定情况下自动调用,提升代码的灵活性和效率。

语言多线程可以大大提升程序效率,C 语言中多线程的实现方式主要有四种:创建独立进程:创建多个独立运行的进程,每个进程拥有自己的内存空间。伪多线程:在一个进程中创建多个执行流,这些执行流共享同一内存空间,并交替执行。多线程库:使用pthreads等多线程库创建和管理线程,提供了丰富的线程操作函数。协程:一种轻量级的多线程实现,将任务划分成小的子任务,轮流执行。

在PHP8 中,match表达式是一种新的控制结构,用于根据表达式的值返回不同的结果。1)它类似于switch语句,但返回值而非执行语句块。2)match表达式使用严格比较(===),提升了安全性。3)它避免了switch语句中可能的break遗漏问题,增强了代码的简洁性和可读性。

解决 Photoshop 启动慢的问题需要多管齐下,包括:升级硬件(内存、固态硬盘、CPU);卸载过时或不兼容的插件;定期清理系统垃圾和过多的后台程序;谨慎关闭无关紧要的程序;启动时避免打开大量文件。

多线程是计算机编程中的重要技术,用来提升程序执行效率。在 C 语言中,有多种实现多线程的方式,包括线程库、POSIX 线程和 Windows API。
