PHP 访问 LDAP

Jul 30, 2016 pm 01:31 PM
connect ldap quot server

LDAP 的全称是“轻量级目录访问协议(Lightweight Directory Access Protocol)”,是一种简单的目录协议。所谓目录,是一种专门的数据库,可以用来服务于任何应用程序。在企业应用中使用 LDAP可以让企业范围内的所有应用程序LDAP 目录中获取信息,应用程序可以从网络上直接从 LDAP 目录获取信息,而不局限于操作系统与服务器的类型。这里主要介绍如何使用 PHP 来访问 LDAP。连接 LDAP 服务器PHP 中用于连接 LDAP 服务器的函数是 ldap_connect,其语法格式如下所示。

1<tdbitstream vera sans mono new font-size:1em direction:ltr white-space:pre background:none><codebitstream vera sans mono new font-size:1em direction:ltr display:inline background:none>ldap_connect([string hostname [, int port]])</codebitstream></tdbitstream></codebitstream></tdbitstream></tr></tbody></table> <plucida sans unicode yahei ms line-height:18.2px>其中,hostname 是 LDAP 服务器所在的主机地址,port 是 LDAP 服务器的端口号。以下代码实现了对位于 192.168.3.1 地址的 LDAP 服务器的连接。<divbitstream vera sans mono new direction:ltr><p></p> <p></p> <table><tbody><tr><tdbitstream vera sans mono new font-size:1em direction:ltr color:rgb background:none><codebitstream vera sans mono new font-size:1em direction:ltr display:block background:none>1<tdbitstream vera sans mono new font-size:1em direction:ltr white-space:pre background:none><codebitstream vera sans mono new font-size:1em direction:ltr display:inline background:none><?php

2<tdbitstream vera sans mono new font-size:1em direction:ltr white-space:pre background:none><codebitstream vera sans mono new font-size:1em direction:ltr display:inline background:none>$ldap_host<codebitstream vera sans mono new font-size:1em direction:ltr display:inline background:none>= <codebitstream vera sans mono new font-size:1em direction:ltr display:inline background:none>"ldap://192.168.3.1"<codebitstream vera sans mono new font-size:1em direction:ltr display:inline background:none>;//LDAP 服务器地址</codebitstream></codebitstream></codebitstream></codebitstream></tdbitstream></codebitstream></tdbitstream></tr></tbody></table> <p></p> <table><tbody><tr><tdbitstream vera sans mono new font-size:1em direction:ltr color:rgb background:none><codebitstream vera sans mono new font-size:1em direction:ltr display:block background:none>3<tdbitstream vera sans mono new font-size:1em direction:ltr white-space:pre background:none><codebitstream vera sans mono new font-size:1em direction:ltr display:inline background:none>$ldap_port<codebitstream vera sans mono new font-size:1em direction:ltr display:inline background:none>= <codebitstream vera sans mono new font-size:1em direction:ltr display:inline background:none>"389"<codebitstream vera sans mono new font-size:1em direction:ltr display:inline background:none>;<codebitstream vera sans mono new font-size:1em direction:ltr display:inline background:none>//LDAP 服务器端口号</codebitstream></codebitstream></codebitstream></codebitstream></codebitstream></tdbitstream></codebitstream></tdbitstream></tr></tbody></table> <p></p> <table><tbody><tr><tdbitstream vera sans mono new font-size:1em direction:ltr color:rgb background:none><codebitstream vera sans mono new font-size:1em direction:ltr display:block background:none>4<tdbitstream vera sans mono new font-size:1em direction:ltr white-space:pre background:none><codebitstream vera sans mono new font-size:1em direction:ltr display:inline background:none>$ldap_conn<codebitstream vera sans mono new font-size:1em direction:ltr display:inline background:none>= ldap_connect(<codebitstream vera sans mono new font-size:1em direction:ltr display:inline background:none>$ldap_host<codebitstream vera sans mono new font-size:1em direction:ltr display:inline background:none>, <codebitstream vera sans mono new font-size:1em direction:ltr display:inline background:none>$ldap_port<codebitstream vera sans mono new font-size:1em direction:ltr display:inline background:none>) <codebitstream vera sans mono new font-weight:bold font-size:1em direction:ltr display:inline background:none>or<codebitstream vera sans mono new font-weight:bold font-size:1em direction:ltr display:inline background:none>die<codebitstream vera sans mono new font-size:1em direction:ltr display:inline background:none>(<codebitstream vera sans mono new font-size:1em direction:ltr display:inline background:none>"Can't connect to LDAP server"<codebitstream vera sans mono new font-size:1em direction:ltr display:inline background:none>);<codebitstream vera sans mono new font-size:1em direction:ltr display:inline background:none>//建立与 LDAP 服务器的连接</codebitstream></codebitstream></codebitstream></codebitstream></codebitstream></codebitstream></codebitstream></codebitstream></codebitstream></codebitstream></codebitstream></codebitstream></tdbitstream></codebitstream></tdbitstream></tr></tbody></table> <p></p> <table><tbody><tr><tdbitstream vera sans mono new font-size:1em direction:ltr color:rgb background:none><codebitstream vera sans mono new font-size:1em direction:ltr display:block background:none>5<tdbitstream vera sans mono new font-size:1em direction:ltr white-space:pre background:none><codebitstream vera sans mono new font-size:1em direction:ltr display:inline background:none>?></codebitstream></tdbitstream></codebitstream></tdbitstream></tr></tbody></table> <plucida sans unicode yahei ms line-height:18.2px>与前面介绍过的方法类似,上面的代码使用了“or die”来美化错误信息。<plucida sans unicode yahei ms line-height:18.2px><span>绑定 LDAP 服务器</span><plucida sans unicode yahei ms line-height:18.2px>绑定 LDAP 服务器的含义是使用特定的用户名或密码来登陆 LDAP 服务器。PHP 中用于绑定 LDAP服务器的函数是 ldap_bind,其语法格式如下所示。<divbitstream vera sans mono new direction:ltr><p></p> <p></p> <table><tbody><tr><tdbitstream vera sans mono new font-size:1em direction:ltr color:rgb background:none><codebitstream vera sans mono new font-size:1em direction:ltr display:block background:none>1<tdbitstream vera sans mono new font-size:1em direction:ltr white-space:pre background:none><codebitstream vera sans mono new font-size:1em direction:ltr display:inline background:none>ldap_bind(ldap_conn [, string username [, string password]])</codebitstream></tdbitstream></codebitstream></tdbitstream></tr></tbody></table> <plucida sans unicode yahei ms line-height:18.2px>其中,ldap_conn 是前面连接 LDAP 服务器时创建的连接对象,username 是登陆 LDAP 服务器时使用的用户名,password 是登陆时所用的密码。以下代码实现了对位于 192.168.3.1 地址的 LDAP 服务器的绑定。<divbitstream vera sans mono new direction:ltr><p></p> <p></p> <table><tbody><tr><tdbitstream vera sans mono new font-size:1em direction:ltr color:rgb background:none><codebitstream vera sans mono new font-size:1em direction:ltr display:block background:none>1<tdbitstream vera sans mono new font-size:1em direction:ltr white-space:pre background:none><codebitstream vera sans mono new font-size:1em direction:ltr display:inline background:none><?php

2<tdbitstream vera sans mono new font-size:1em direction:ltr white-space:pre background:none><codebitstream vera sans mono new font-size:1em direction:ltr display:inline background:none>$ldap_host<codebitstream vera sans mono new font-size:1em direction:ltr display:inline background:none>= <codebitstream vera sans mono new font-size:1em direction:ltr display:inline background:none>"ldap://192.168.3.1"<codebitstream vera sans mono new font-size:1em direction:ltr display:inline background:none>;//LDAP 服务器地址</codebitstream></codebitstream></codebitstream></codebitstream></tdbitstream></codebitstream></tdbitstream></tr></tbody></table> <p></p> <table><tbody><tr><tdbitstream vera sans mono new font-size:1em direction:ltr color:rgb background:none><codebitstream vera sans mono new font-size:1em direction:ltr display:block background:none>3<tdbitstream vera sans mono new font-size:1em direction:ltr white-space:pre background:none><codebitstream vera sans mono new font-size:1em direction:ltr display:inline background:none>$ldap_port<codebitstream vera sans mono new font-size:1em direction:ltr display:inline background:none>= <codebitstream vera sans mono new font-size:1em direction:ltr display:inline background:none>"389"<codebitstream vera sans mono new font-size:1em direction:ltr display:inline background:none>;<codebitstream vera sans mono new font-size:1em direction:ltr display:inline background:none>//LDAP 服务器端口号</codebitstream></codebitstream></codebitstream></codebitstream></codebitstream></tdbitstream></codebitstream></tdbitstream></tr></tbody></table> <p></p> <table><tbody><tr><tdbitstream vera sans mono new font-size:1em direction:ltr color:rgb background:none><codebitstream vera sans mono new font-size:1em direction:ltr display:block background:none>4<tdbitstream vera sans mono new font-size:1em direction:ltr white-space:pre background:none><codebitstream vera sans mono new font-size:1em direction:ltr display:inline background:none>$ldap_user<codebitstream vera sans mono new font-size:1em direction:ltr display:inline background:none>= <codebitstream vera sans mono new font-size:1em direction:ltr display:inline background:none>""<codebitstream vera sans mono new font-size:1em direction:ltr display:inline background:none>; <codebitstream vera sans mono new font-size:1em direction:ltr display:inline background:none>//设定服务器用户名</codebitstream></codebitstream></codebitstream></codebitstream></codebitstream></tdbitstream></codebitstream></tdbitstream></tr></tbody></table> <p></p> <table><tbody><tr><tdbitstream vera sans mono new font-size:1em direction:ltr color:rgb background:none><codebitstream vera sans mono new font-size:1em direction:ltr display:block background:none>5<tdbitstream vera sans mono new font-size:1em direction:ltr white-space:pre background:none><codebitstream vera sans mono new font-size:1em direction:ltr display:inline background:none>$ldap_pwd<codebitstream vera sans mono new font-size:1em direction:ltr display:inline background:none>= <codebitstream vera sans mono new font-size:1em direction:ltr display:inline background:none>""<codebitstream vera sans mono new font-size:1em direction:ltr display:inline background:none>; <codebitstream vera sans mono new font-size:1em direction:ltr display:inline background:none>//设定服务器密码</codebitstream></codebitstream></codebitstream></codebitstream></codebitstream></tdbitstream></codebitstream></tdbitstream></tr></tbody></table> <p></p> <table><tbody><tr><tdbitstream vera sans mono new font-size:1em direction:ltr color:rgb background:none><codebitstream vera sans mono new font-size:1em direction:ltr display:block background:none>6<tdbitstream vera sans mono new font-size:1em direction:ltr white-space:pre background:none><codebitstream vera sans mono new font-size:1em direction:ltr display:inline background:none>$ldap_conn<codebitstream vera sans mono new font-size:1em direction:ltr display:inline background:none>= ldap_connect(<codebitstream vera sans mono new font-size:1em direction:ltr display:inline background:none>$ldap_host<codebitstream vera sans mono new font-size:1em direction:ltr display:inline background:none>, <codebitstream vera sans mono new font-size:1em direction:ltr display:inline background:none>$ldap_port<codebitstream vera sans mono new font-size:1em direction:ltr display:inline background:none>) <codebitstream vera sans mono new font-size:1em direction:ltr display:inline background:none>//建立与 LDAP 服务器的连接</codebitstream></codebitstream></codebitstream></codebitstream></codebitstream></codebitstream></codebitstream></tdbitstream></codebitstream></tdbitstream></tr></tbody></table> <p></p> <table><tbody><tr><tdbitstream vera sans mono new font-size:1em direction:ltr color:rgb background:none><codebitstream vera sans mono new font-size:1em direction:ltr display:block background:none>7<tdbitstream vera sans mono new font-size:1em direction:ltr white-space:pre background:none><codebitstream vera sans mono new font-weight:bold font-size:1em direction:ltr display:inline background:none>or<codebitstream vera sans mono new font-weight:bold font-size:1em direction:ltr display:inline background:none>die<codebitstream vera sans mono new font-size:1em direction:ltr display:inline background:none>(<codebitstream vera sans mono new font-size:1em direction:ltr display:inline background:none>"Can't connect to LDAP server"<codebitstream vera sans mono new font-size:1em direction:ltr display:inline background:none>);</codebitstream></codebitstream></codebitstream></codebitstream></codebitstream></tdbitstream></codebitstream></tdbitstream></tr></tbody></table> <p></p> <table><tbody><tr><tdbitstream vera sans mono new font-size:1em direction:ltr color:rgb background:none><codebitstream vera sans mono new font-size:1em direction:ltr display:block background:none>8<tdbitstream vera sans mono new font-size:1em direction:ltr white-space:pre background:none><codebitstream vera sans mono new font-size:1em direction:ltr display:inline background:none>ldap_bind(<codebitstream vera sans mono new font-size:1em direction:ltr display:inline background:none>$ldap_conn<codebitstream vera sans mono new font-size:1em direction:ltr display:inline background:none>, <codebitstream vera sans mono new font-size:1em direction:ltr display:inline background:none>$ldap_user<codebitstream vera sans mono new font-size:1em direction:ltr display:inline background:none>, <codebitstream vera sans mono new font-size:1em direction:ltr display:inline background:none>$ldap_pwd<codebitstream vera sans mono new font-size:1em direction:ltr display:inline background:none>) <codebitstream vera sans mono new font-weight:bold font-size:1em direction:ltr display:inline background:none>or<codebitstream vera sans mono new font-weight:bold font-size:1em direction:ltr display:inline background:none>die<codebitstream vera sans mono new font-size:1em direction:ltr display:inline background:none>(<codebitstream vera sans mono new font-size:1em direction:ltr display:inline background:none>"Can't bind to LDAP server."<codebitstream vera sans mono new font-size:1em direction:ltr display:inline background:none>);<codebitstream vera sans mono new font-size:1em direction:ltr display:inline background:none>//与服务器绑定</codebitstream></codebitstream></codebitstream></codebitstream></codebitstream></codebitstream></codebitstream></codebitstream></codebitstream></codebitstream></codebitstream></codebitstream></codebitstream></tdbitstream></codebitstream></tdbitstream></tr></tbody></table> <p></p> <table><tbody><tr><tdbitstream vera sans mono new font-size:1em direction:ltr color:rgb background:none><codebitstream vera sans mono new font-size:1em direction:ltr display:block background:none>9<tdbitstream vera sans mono new font-size:1em direction:ltr white-space:pre background:none><codebitstream vera sans mono new font-size:1em direction:ltr display:inline background:none>?></codebitstream></tdbitstream></codebitstream></tdbitstream></tr></tbody></table> <plucida sans unicode yahei ms line-height:18.2px><span>断开 LDAP 服务器</span><plucida sans unicode yahei ms line-height:18.2px>与 LDAP 服务器断开的过程与绑定 LDAP 服务器相反,PHP 中用于绑定 LDAP 服务器的函数是ldap_unbind,其语法格式如下所示。<divbitstream vera sans mono new direction:ltr><p></p> <p></p> <table><tbody><tr><tdbitstream vera sans mono new font-size:1em direction:ltr color:rgb background:none><codebitstream vera sans mono new font-size:1em direction:ltr display:block background:none>1<tdbitstream vera sans mono new font-size:1em direction:ltr white-space:pre background:none><codebitstream vera sans mono new font-size:1em direction:ltr display:inline background:none>ldap_unbind(ldap_conn)</codebitstream></tdbitstream></codebitstream></tdbitstream></tr></tbody></table> <plucida sans unicode yahei ms line-height:18.2px>其中,ldap_conn 是前面连接 LDAP 服务器时创建的连接对象。以下代码在绑定了对位于 192.168.3.1地址的 LDAP 服务器后与其断开连接。<divbitstream vera sans mono new direction:ltr><p></p> <p></p> <table><tbody><tr><tdbitstream vera sans mono new font-size:1em direction:ltr color:rgb background:none><codebitstream vera sans mono new font-size:1em direction:ltr display:block background:none>01<tdbitstream vera sans mono new font-size:1em direction:ltr white-space:pre background:none><codebitstream vera sans mono new font-size:1em direction:ltr display:inline background:none><?php

02<tdbitstream vera sans mono new font-size:1em direction:ltr white-space:pre background:none><codebitstream vera sans mono new font-size:1em direction:ltr display:inline background:none>$ldap_host<codebitstream vera sans mono new font-size:1em direction:ltr display:inline background:none>= <codebitstream vera sans mono new font-size:1em direction:ltr display:inline background:none>"ldap://192.168.3.1"<codebitstream vera sans mono new font-size:1em direction:ltr display:inline background:none>;//LDAP 服务器地址</codebitstream></codebitstream></codebitstream></codebitstream></tdbitstream></codebitstream></tdbitstream></tr></tbody></table> <p></p> <table><tbody><tr><tdbitstream vera sans mono new font-size:1em direction:ltr color:rgb background:none><codebitstream vera sans mono new font-size:1em direction:ltr display:block background:none>03<tdbitstream vera sans mono new font-size:1em direction:ltr white-space:pre background:none><codebitstream vera sans mono new font-size:1em direction:ltr display:inline background:none>$ldap_port<codebitstream vera sans mono new font-size:1em direction:ltr display:inline background:none>= <codebitstream vera sans mono new font-size:1em direction:ltr display:inline background:none>"389"<codebitstream vera sans mono new font-size:1em direction:ltr display:inline background:none>;<codebitstream vera sans mono new font-size:1em direction:ltr display:inline background:none>//LDAP 服务器端口号</codebitstream></codebitstream></codebitstream></codebitstream></codebitstream></tdbitstream></codebitstream></tdbitstream></tr></tbody></table> <p></p> <table><tbody><tr><tdbitstream vera sans mono new font-size:1em direction:ltr color:rgb background:none><codebitstream vera sans mono new font-size:1em direction:ltr display:block background:none>04<tdbitstream vera sans mono new font-size:1em direction:ltr white-space:pre background:none><codebitstream vera sans mono new font-size:1em direction:ltr display:inline background:none>$ldap_user<codebitstream vera sans mono new font-size:1em direction:ltr display:inline background:none>= <codebitstream vera sans mono new font-size:1em direction:ltr display:inline background:none>""<codebitstream vera sans mono new font-size:1em direction:ltr display:inline background:none>;<codebitstream vera sans mono new font-size:1em direction:ltr display:inline background:none>//设定服务器用户名</codebitstream></codebitstream></codebitstream></codebitstream></codebitstream></tdbitstream></codebitstream></tdbitstream></tr></tbody></table> <p></p> <table><tbody><tr><tdbitstream vera sans mono new font-size:1em direction:ltr color:rgb background:none><codebitstream vera sans mono new font-size:1em direction:ltr display:block background:none>05<tdbitstream vera sans mono new font-size:1em direction:ltr white-space:pre background:none><codebitstream vera sans mono new font-size:1em direction:ltr display:inline background:none>$ldap_pwd<codebitstream vera sans mono new font-size:1em direction:ltr display:inline background:none>= <codebitstream vera sans mono new font-size:1em direction:ltr display:inline background:none>""<codebitstream vera sans mono new font-size:1em direction:ltr display:inline background:none>;<codebitstream vera sans mono new font-size:1em direction:ltr display:inline background:none>//设定服务器密码</codebitstream></codebitstream></codebitstream></codebitstream></codebitstream></tdbitstream></codebitstream></tdbitstream></tr></tbody></table> <p></p> <table><tbody><tr><tdbitstream vera sans mono new font-size:1em direction:ltr color:rgb background:none><codebitstream vera sans mono new font-size:1em direction:ltr display:block background:none>06<tdbitstream vera sans mono new font-size:1em direction:ltr white-space:pre background:none><codebitstream vera sans mono new font-size:1em direction:ltr display:inline background:none>$ldap_conn<codebitstream vera sans mono new font-size:1em direction:ltr display:inline background:none>= ldap_connect(<codebitstream vera sans mono new font-size:1em direction:ltr display:inline background:none>$ldap_host<codebitstream vera sans mono new font-size:1em direction:ltr display:inline background:none>, <codebitstream vera sans mono new font-size:1em direction:ltr display:inline background:none>$ldap_port<codebitstream vera sans mono new font-size:1em direction:ltr display:inline background:none>) <codebitstream vera sans mono new font-size:1em direction:ltr display:inline background:none>//建立与 LDAP 服务器的连接</codebitstream></codebitstream></codebitstream></codebitstream></codebitstream></codebitstream></codebitstream></tdbitstream></codebitstream></tdbitstream></tr></tbody></table> <p></p> <table><tbody><tr><tdbitstream vera sans mono new font-size:1em direction:ltr color:rgb background:none><codebitstream vera sans mono new font-size:1em direction:ltr display:block background:none>07<tdbitstream vera sans mono new font-size:1em direction:ltr white-space:pre background:none><codebitstream vera sans mono new font-weight:bold font-size:1em direction:ltr display:inline background:none>or<codebitstream vera sans mono new font-weight:bold font-size:1em direction:ltr display:inline background:none>die<codebitstream vera sans mono new font-size:1em direction:ltr display:inline background:none>(<codebitstream vera sans mono new font-size:1em direction:ltr display:inline background:none>"Can't connect to LDAP server"<codebitstream vera sans mono new font-size:1em direction:ltr display:inline background:none>);</codebitstream></codebitstream></codebitstream></codebitstream></codebitstream></tdbitstream></codebitstream></tdbitstream></tr></tbody></table> <p></p> <table><tbody><tr><tdbitstream vera sans mono new font-size:1em direction:ltr color:rgb background:none><codebitstream vera sans mono new font-size:1em direction:ltr display:block background:none>08<tdbitstream vera sans mono new font-size:1em direction:ltr white-space:pre background:none><codebitstream vera sans mono new font-size:1em direction:ltr display:inline background:none>ldap_bind(<codebitstream vera sans mono new font-size:1em direction:ltr display:inline background:none>$ldap_conn<codebitstream vera sans mono new font-size:1em direction:ltr display:inline background:none>, <codebitstream vera sans mono new font-size:1em direction:ltr display:inline background:none>$ldap_user<codebitstream vera sans mono new font-size:1em direction:ltr display:inline background:none>, <codebitstream vera sans mono new font-size:1em direction:ltr display:inline background:none>$ldap_pwd<codebitstream vera sans mono new font-size:1em direction:ltr display:inline background:none>) <codebitstream vera sans mono new font-size:1em direction:ltr display:inline background:none>//与服务器绑定</codebitstream></codebitstream></codebitstream></codebitstream></codebitstream></codebitstream></codebitstream></codebitstream></tdbitstream></codebitstream></tdbitstream></tr></tbody></table> <p></p> <table><tbody><tr><tdbitstream vera sans mono new font-size:1em direction:ltr color:rgb background:none><codebitstream vera sans mono new font-size:1em direction:ltr display:block background:none>09<tdbitstream vera sans mono new font-size:1em direction:ltr white-space:pre background:none><codebitstream vera sans mono new font-weight:bold font-size:1em direction:ltr display:inline background:none>or<codebitstream vera sans mono new font-weight:bold font-size:1em direction:ltr display:inline background:none>die<codebitstream vera sans mono new font-size:1em direction:ltr display:inline background:none>(<codebitstream vera sans mono new font-size:1em direction:ltr display:inline background:none>"Can't bind to LDAP server."<codebitstream vera sans mono new font-size:1em direction:ltr display:inline background:none>);</codebitstream></codebitstream></codebitstream></codebitstream></codebitstream></tdbitstream></codebitstream></tdbitstream></tr></tbody></table> <p></p> <table><tbody><tr><tdbitstream vera sans mono new font-size:1em direction:ltr color:rgb background:none><codebitstream vera sans mono new font-size:1em direction:ltr display:block background:none>10<tdbitstream vera sans mono new font-size:1em direction:ltr white-space:pre background:none><codebitstream vera sans mono new font-size:1em direction:ltr display:inline background:none>ldap_unbind(<codebitstream vera sans mono new font-size:1em direction:ltr display:inline background:none>$ldap_conn<codebitstream vera sans mono new font-size:1em direction:ltr display:inline background:none>) <codebitstream vera sans mono new font-weight:bold font-size:1em direction:ltr display:inline background:none>or<codebitstream vera sans mono new font-weight:bold font-size:1em direction:ltr display:inline background:none>die<codebitstream vera sans mono new font-size:1em direction:ltr display:inline background:none>(<codebitstream vera sans mono new font-size:1em direction:ltr display:inline background:none>"Can't unbind from LDAP server."<codebitstream vera sans mono new font-size:1em direction:ltr display:inline background:none>);  <codebitstream vera sans mono new font-size:1em direction:ltr display:inline background:none>//与服务器断开连接</codebitstream></codebitstream></codebitstream></codebitstream></codebitstream></codebitstream></codebitstream></codebitstream></codebitstream></tdbitstream></codebitstream></tdbitstream></tr></tbody></table> <p></p> <table><tbody><tr><tdbitstream vera sans mono new font-size:1em direction:ltr color:rgb background:none><codebitstream vera sans mono new font-size:1em direction:ltr display:block background:none>11<tdbitstream vera sans mono new font-size:1em direction:ltr white-space:pre background:none><codebitstream vera sans mono new font-size:1em direction:ltr display:inline background:none>?></codebitstream></tdbitstream></codebitstream></tdbitstream></tr></tbody></table> <plucida sans unicode yahei ms line-height:18.2px><span>查询 LDAP 目录内容</span><plucida sans unicode yahei ms line-height:18.2px>查询 LDAP 目录使用 ldap_search 函数来实现,其语法格式如下所示。<divbitstream vera sans mono new direction:ltr><p></p> <p></p> <table><tbody><tr><tdbitstream vera sans mono new font-size:1em direction:ltr color:rgb background:none><codebitstream vera sans mono new font-size:1em direction:ltr display:block background:none>1<tdbitstream vera sans mono new font-size:1em direction:ltr white-space:pre background:none><codebitstream vera sans mono new font-size:1em direction:ltr display:inline background:none>ldap_search(ldap_conn, base_dn, conditions)</codebitstream></tdbitstream></codebitstream></tdbitstream></tr></tbody></table> <plucida sans unicode yahei ms line-height:18.2px>其中,ldap_conn 是前面连接 LDAP 服务器时创建的连接对象。base_dn 是 LDAP 服务器的查询主键。conditions 是用于 LDAP 目录查询所用的条件。该函数返回一个结果对象,该结果对象保存查询到的所有记录。对于这个结果对象,可以使用 ldap_get_entries 函数进行简单的读取,其语法格式如下所示。<divbitstream vera sans mono new direction:ltr><p></p> <p></p> <table><tbody><tr><tdbitstream vera sans mono new font-size:1em direction:ltr color:rgb background:none><codebitstream vera sans mono new font-size:1em direction:ltr display:block background:none>1<tdbitstream vera sans mono new font-size:1em direction:ltr white-space:pre background:none><codebitstream vera sans mono new font-size:1em direction:ltr display:inline background:none>ldap_get_entries(ldap_conn, result)</codebitstream></tdbitstream></codebitstream></tdbitstream></tr></tbody></table> <plucida sans unicode yahei ms line-height:18.2px>其中,ldap_conn 是前面连接 LDAP 服务器时创建的连接对象,result 是前面查询 LDAP 目录时返回的对象。该函数返回一个数组,包含所有的结果记录。以下代码实现了对服务器上的内容进行查询。<divbitstream vera sans mono new direction:ltr><p></p> <p></p> <table><tbody><tr><tdbitstream vera sans mono new font-size:1em direction:ltr color:rgb background:none><codebitstream vera sans mono new font-size:1em direction:ltr display:block background:none>01<tdbitstream vera sans mono new font-size:1em direction:ltr white-space:pre background:none><codebitstream vera sans mono new font-size:1em direction:ltr display:inline background:none><?php

02$ldap_host= "ldap://192.168.3.1";//LDAP 服务器地址

03$ldap_port= "389";//LDAP 服务器端口号

04$ldap_user= "";//设定服务器用户名

05$ldap_pwd= "";//设定服务器密码

06$ldap_conn= ldap_connect($ldap_host, $ldap_port) ordie("Can't connect to LDAP server");//建立与 LDAP 服务器的连接

07ldap_bind($ldap_conn, $ldap_user, $ldap_pwd) ordie("Can't bind to LDAP server.");//与服务器绑定

08$base_dn= "ou=company,o=depart";//定义要进行查询的目录主键

09$filter_col= "mail";//定义用于查询的列

10
Erklärung dieser Website
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn

Heiße KI -Werkzeuge

Undresser.AI Undress

Undresser.AI Undress

KI-gestützte App zum Erstellen realistischer Aktfotos

AI Clothes Remover

AI Clothes Remover

Online-KI-Tool zum Entfernen von Kleidung aus Fotos.

Undress AI Tool

Undress AI Tool

Ausziehbilder kostenlos

Clothoff.io

Clothoff.io

KI-Kleiderentferner

AI Hentai Generator

AI Hentai Generator

Erstellen Sie kostenlos Ai Hentai.

Heißer Artikel

R.E.P.O. Energiekristalle erklärten und was sie tun (gelber Kristall)
3 Wochen vor By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Beste grafische Einstellungen
3 Wochen vor By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. So reparieren Sie Audio, wenn Sie niemanden hören können
3 Wochen vor By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: Wie man alles in Myrise freischaltet
4 Wochen vor By 尊渡假赌尊渡假赌尊渡假赌

Heiße Werkzeuge

Notepad++7.3.1

Notepad++7.3.1

Einfach zu bedienender und kostenloser Code-Editor

SublimeText3 chinesische Version

SublimeText3 chinesische Version

Chinesische Version, sehr einfach zu bedienen

Senden Sie Studio 13.0.1

Senden Sie Studio 13.0.1

Leistungsstarke integrierte PHP-Entwicklungsumgebung

Dreamweaver CS6

Dreamweaver CS6

Visuelle Webentwicklungstools

SublimeText3 Mac-Version

SublimeText3 Mac-Version

Codebearbeitungssoftware auf Gottesniveau (SublimeText3)

So führen Sie Range-Übungen mit Bee-Box-LDAP-Injektion durch So führen Sie Range-Übungen mit Bee-Box-LDAP-Injektion durch May 13, 2023 am 09:49 AM

Wenn die Essenz der SQL-Injektion darin besteht, Zeichenfolgen zu spleißen, ist die LDAP-Injektion als eine Art Injektion keine Ausnahme. Interessanter ist, dass es sich um das Spleißen von Klammern handelt (SQL-Injektion). verkettet auch Klammern, es ist jedoch konventioneller zu sagen, dass es Zeichenfolgen verkettet). Im Kapitel zur Umgebungskonfiguration wurde die Konfiguration der LDAP-Umgebung in Bee-Box ausführlich besprochen. Im Übungskapitel zum Schießstand geht es mehr um den Verbindungsprozess zwischen PHP und LDAP, die Einführung der in der Mitte verwendeten Sonderfunktionen einige Techniken zum Zusammenfügen von Klammern. Lassen Sie uns zunächst über den Anmeldevorgang des LDAP-Schießstands in bwapp sprechen: Erstens handelt es sich um eine LDAP-Anmeldeschnittstelle, die URL lautet http://192.168.3.184/bW

Wie man die LDAP-Injektion versteht Wie man die LDAP-Injektion versteht May 22, 2023 pm 09:47 PM

1. LDAP-Injection LDAP (Light Directory Access Portocol) ist ein leichtes Verzeichniszugriffsprotokoll, das auf dem X.500-Standard basiert. Es stellt Dienste und Protokolle für den Zugriff auf Verzeichnisdatenbanken bereit. Es wird häufig zur Bildung von Verzeichnisdiensten mit Verzeichnisdatenbanken verwendet. Das Verzeichnis ist eine professionelle verteilte Datenbank, die für Abfragen, Durchsuchen und Suchen optimiert ist. Es organisiert Daten in einer Baumstruktur, ähnlich dem Dateiverzeichnis in Linux/Unix-Systemen. Daten, die nicht häufig geändert werden, wie z. B. öffentliche Zertifikate, Sicherheitsschlüssel und Informationen zu physischen Unternehmensgeräten, eignen sich für die Speicherung im Verzeichnis. LDAP kann als Suchprotokoll verstanden werden, das SQL ähnelt und über eine Abfragesyntax verfügt, jedoch auch das Risiko von Injektionsangriffen birgt. Die LDAP-Injection bezieht sich auf den Client

Anleitung zum Installieren, Deinstallieren und Zurücksetzen des Windows-Server-Backups Anleitung zum Installieren, Deinstallieren und Zurücksetzen des Windows-Server-Backups Mar 06, 2024 am 10:37 AM

WindowsServerBackup ist eine Funktion des WindowsServer-Betriebssystems, die Benutzern dabei helfen soll, wichtige Daten und Systemkonfigurationen zu schützen und vollständige Sicherungs- und Wiederherstellungslösungen für kleine, mittlere und große Unternehmen bereitzustellen. Nur Benutzer, die Server2022 und höher ausführen, können diese Funktion nutzen. In diesem Artikel erklären wir, wie Sie WindowsServerBackup installieren, deinstallieren oder zurücksetzen. So setzen Sie die Windows Server-Sicherung zurück: Wenn Sie Probleme mit der Sicherung Ihres Servers haben, die Sicherung zu lange dauert oder Sie nicht auf gespeicherte Dateien zugreifen können, können Sie die Sicherungseinstellungen Ihres Windows Servers zurücksetzen. Um Windows zurückzusetzen

So konfigurieren Sie die Umgebung für die Bee-Box-LDAP-Injektion So konfigurieren Sie die Umgebung für die Bee-Box-LDAP-Injektion May 12, 2023 pm 08:37 PM

1. Überblick Nach meinem Lernprozess muss ich das Modell und die Schwachstelle meines Webangriffs kennen. Jetzt bin ich auf eine unerwartete Situation gestoßen. Das erste Mal, dass ich LDAP gesehen habe Ich habe ein unbeliebtes (autorisiertes) gefunden und mein Interesse daran geweckt. Das Konzept von LDAP: Vollständiger Name: Lightweight Directory Access Protocol (Lightweight Directory Access Protocol), Merkmale: Ich werde nicht über das Protokoll sprechen, es ist zu esoterisch, es kann als Datenbank zum Speichern von Daten verstanden werden, seine Besonderheit ist das Es handelt sich um einen Baum in Form einer Datenbank

Lösung für PHP Schwerwiegender Fehler: Aufruf der undefinierten Funktion ldap_bind() Lösung für PHP Schwerwiegender Fehler: Aufruf der undefinierten Funktion ldap_bind() Jun 22, 2023 pm 11:37 PM

Bei der Entwicklung von Webanwendungen mit PHP müssen wir häufig die LDAP-Authentifizierung verwenden, um den Anwendungszugriff zu schützen. Wenn wir jedoch versuchen, die LDAP-Funktionalität von PHP zur Implementierung der Authentifizierung zu verwenden, kann es in einigen Fällen zu der folgenden Fehlermeldung kommen: „PHPFatalerror:Calltoundefinedfunctionldap_bind()“. Diese Fehlermeldung tritt normalerweise auf, wenn eine Anwendung die Funktion ldap_bind() aufruft

Vorschauversion von Windows Server 2025 begrüßt Update, Microsoft verbessert Insiders-Testerlebnis Vorschauversion von Windows Server 2025 begrüßt Update, Microsoft verbessert Insiders-Testerlebnis Feb 19, 2024 pm 02:36 PM

Anlässlich der Veröffentlichung der Build 26040-Version von Windows Server gab Microsoft den offiziellen Namen des Produkts bekannt: Windows Server 2025. Außerdem wurde die Windows11WindowsInsiderCanaryChannel-Version build26040 eingeführt. Einige Freunde erinnern sich vielleicht noch daran, dass vor vielen Jahren jemand Windows NT erfolgreich vom Workstation-Modus in den Server-Modus umgestellt hat und dabei die Gemeinsamkeiten verschiedener Versionen von Microsoft-Betriebssystemen aufgezeigt hat. Zwar gibt es deutliche Unterschiede zwischen Microsofts aktueller Version des Server-Betriebssystems und Windows 11, doch wer auf die Details achtet, dürfte neugierig sein: Warum Windows Server die Marke aktualisiert hat,

php提交表单通过后,弹出的对话框怎样在当前页弹出,该如何解决 php提交表单通过后,弹出的对话框怎样在当前页弹出,该如何解决 Jun 13, 2016 am 10:23 AM

php提交表单通过后,弹出的对话框怎样在当前页弹出php提交表单通过后,弹出的对话框怎样在当前页弹出而不是在空白页弹出?想实现这样的效果:而不是空白页弹出:------解决方案--------------------如果你的验证用PHP在后端,那么就用Ajax;仅供参考:HTML code

So ändern Sie den Nginx-Versionsnamen, um jeden Webserver zu verschleiern So ändern Sie den Nginx-Versionsnamen, um jeden Webserver zu verschleiern May 14, 2023 pm 09:19 PM

So ändern Sie den Standardnamen von Nginx: Sie können ihn ein wenig verschleiern oder installieren Tipp: Im Allgemeinen werden Änderungen vorgenommen, bevor Nginx kompiliert wird. Nach der Änderung muss der Code wie folgt neu kompiliert werden: scr/core/nginx.conf#definenginx_version"1.4.7"#definenginx_ver"nginx/"n

See all articles