찾다
PHP 访问 LDAPJul 30, 2016 pm 01:31 PM
connectldapquotserver

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
성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
如何进行bee-box LDAP注入的靶场练习如何进行bee-box LDAP注入的靶场练习May 13, 2023 am 09:49 AM

如果说sql注入的本质是拼接字符串的话,那么一切可以注入的本质都是拼接字符串,LDAP注入作为注入的一种也不例外,更有趣一点的说它是在拼接圆括号(sql注入也拼接圆括号,但是更习惯性的是说它拼接字符串)。在环境配置篇里面已经很详细的说了bee-box中ldap环境的配置,靶场练习篇更多的是php与ldap的连接过程,中间使用的特殊函数介绍以及圆括号拼接的一些技巧。下面先说一下bwapp中ldap靶场的登录过程:首先这是一个LDAP的登录界面,URL是http://192.168.3.184/bW

如何安装、卸载、重置Windows服务器备份如何安装、卸载、重置Windows服务器备份Mar 06, 2024 am 10:37 AM

WindowsServerBackup是WindowsServer操作系统自带的一个功能,旨在帮助用户保护重要数据和系统配置,并为中小型和企业级企业提供完整的备份和恢复解决方案。只有运行Server2022及更高版本的用户才能使用这一功能。在本文中,我们将介绍如何安装、卸载或重置WindowsServerBackup。如何重置Windows服务器备份如果您的服务器备份遇到问题,备份所需时间过长,或无法访问已存储的文件,那么您可以考虑重新设置WindowsServer备份设置。要重置Windows

LDAP注入该如何理解LDAP注入该如何理解May 22, 2023 pm 09:47 PM

1、LDAP注入LDAP(LightDirectoryAccessPortocol)是基于X.500标准的轻量级目录访问协议,提供访问目录数据库方法的服务和协议,常用于与目录数据库组成目录服务。其中目录是一个为查询、浏览和搜索而优化的专业分布式数据库,它呈树状结构组织数据,类似于Linux/Unix系统中的文件目录。公用证书、安全密钥、公司的物理设备信息等修改并不频繁的数据适合存储在目录中。可以将LDAP理解为一种搜索协议,它类似于SQL,拥有查询语法,也存在被注入攻击的风险。LDAP注入是指客

PHP Fatal error: Call to undefined function ldap_bind()的解决方法PHP Fatal error: Call to undefined function ldap_bind()的解决方法Jun 22, 2023 pm 11:37 PM

在使用PHP开发Web应用程序时,我们经常需要使用LDAP身份验证来保护应用程序的访问。然而,在有些情况下,当我们尝试使用PHP的LDAP功能来实现身份验证时,可能会遇到以下错误消息:"PHPFatalerror:Calltoundefinedfunctionldap_bind()"。这种错误消息通常会在应用程序调用ldap_bind()函数

如何进行bee-box LDAP注入的环境配置如何进行bee-box LDAP注入的环境配置May 12, 2023 pm 08:37 PM

一、综述按照我的学习过程来说,我必须知道我进行web攻击的这个模型和漏洞的原理是什么,现在我就碰到个冷门,最初见到LDAP时是某次在某国企的渗透测试中发现一个冷门(经过授权的),激起了我对它的兴趣。LDAP的概念:全称:轻量级目录访问协议(LightweightDirectoryAccessProtocolt),特点:协议什么的就不说了,太深奥,可以把它理解为一种存储数据的数据库,它的特殊在于它是一种树状的数据库,首先这个数据库的名字相当于树根(即DB=dc),然后从树根到某个叶子节点过程所经过

Windows Server 2025预览版迎来更新,微软改善Insiders测试体验Windows Server 2025预览版迎来更新,微软改善Insiders测试体验Feb 19, 2024 pm 02:36 PM

在发布WindowsServer的build26040版本之际,微软公布了该产品的官方名称:WindowsServer2025。一同推出的,还有Windows11WindowsInsiderCanaryChannel版本的build26040。有些朋友可能还记得,多年前有人成功将WindowsNT从工作站模式转换为服务器模式,显示微软操作系统各版本之间的共性。尽管现在微软的服务器操作系统版本和Windows11之间有明显区别,但关注细节的人可能会好奇:为什么WindowsServer更新了品牌,

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

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

怎么修改Nginx版本名称伪装任意web server怎么修改Nginx版本名称伪装任意web serverMay 14, 2023 pm 09:19 PM

如何修改nginx默认的名称,可以稍微的伪装一下,也可以装x一般来说修改3个位置,一个是nginx.h、另一个是ngx_http_header_filter_module.c、还有一个ngx_http_special_response.c。提示:一般修改都是在nginx编译之前修改,修改完了之后需要重新编译代码如下:scr/core/nginx.conf#definenginx_version"1.4.7"#definenginx_ver"nginx/"n

See all articles

핫 AI 도구

Undresser.AI Undress

Undresser.AI Undress

사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover

AI Clothes Remover

사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool

Undress AI Tool

무료로 이미지를 벗다

Clothoff.io

Clothoff.io

AI 옷 제거제

AI Hentai Generator

AI Hentai Generator

AI Hentai를 무료로 생성하십시오.

뜨거운 도구

DVWA

DVWA

DVWA(Damn Vulnerable Web App)는 매우 취약한 PHP/MySQL 웹 애플리케이션입니다. 주요 목표는 보안 전문가가 법적 환경에서 자신의 기술과 도구를 테스트하고, 웹 개발자가 웹 응용 프로그램 보안 프로세스를 더 잘 이해할 수 있도록 돕고, 교사/학생이 교실 환경 웹 응용 프로그램에서 가르치고 배울 수 있도록 돕는 것입니다. 보안. DVWA의 목표는 다양한 난이도의 간단하고 간단한 인터페이스를 통해 가장 일반적인 웹 취약점 중 일부를 연습하는 것입니다. 이 소프트웨어는

PhpStorm 맥 버전

PhpStorm 맥 버전

최신(2018.2.1) 전문 PHP 통합 개발 도구

SublimeText3 Mac 버전

SublimeText3 Mac 버전

신 수준의 코드 편집 소프트웨어(SublimeText3)

MinGW - Windows용 미니멀리스트 GNU

MinGW - Windows용 미니멀리스트 GNU

이 프로젝트는 osdn.net/projects/mingw로 마이그레이션되는 중입니다. 계속해서 그곳에서 우리를 팔로우할 수 있습니다. MinGW: GCC(GNU Compiler Collection)의 기본 Windows 포트로, 기본 Windows 애플리케이션을 구축하기 위한 무료 배포 가능 가져오기 라이브러리 및 헤더 파일로 C99 기능을 지원하는 MSVC 런타임에 대한 확장이 포함되어 있습니다. 모든 MinGW 소프트웨어는 64비트 Windows 플랫폼에서 실행될 수 있습니다.

ZendStudio 13.5.1 맥

ZendStudio 13.5.1 맥

강력한 PHP 통합 개발 환경