函数名:ldap_next_reference()
适用版本:PHP 4 >= 4.0.5, PHP 5, PHP 7
用法:ldap_next_reference() 函数用于获取下一个引用结果项。当在搜索操作中返回引用时,可以使用该函数来遍历引用链。
语法:bool ldap_next_reference ( resource $ldap_link , resource $result_entry_identifier )
参数:
- $ldap_link:LDAP 连接标识符,由 ldap_connect() 返回。
- $result_entry_identifier:结果项标识符,由 ldap_first_reference() 或 ldap_next_reference() 返回。
返回值:成功时返回 true,失败时返回 false。
示例:
// 创建 LDAP 连接
$ldapconn = ldap_connect("ldap.example.com");
if ($ldapconn) {
// 绑定 LDAP 用户
$ldapbind = ldap_bind($ldapconn, "cn=admin,dc=example,dc=com", "password");
if ($ldapbind) {
// 执行 LDAP 搜索操作
$ldapsearch = ldap_search($ldapconn, "dc=example,dc=com", "cn=John Doe");
// 获取第一个引用结果项
$reference = ldap_first_reference($ldapconn, $ldapsearch);
// 遍历引用链
while ($reference) {
// 处理引用结果项
// 获取下一个引用结果项
$reference = ldap_next_reference($ldapconn, $reference);
}
// 释放搜索结果
ldap_free_result($ldapsearch);
}
// 关闭 LDAP 连接
ldap_close($ldapconn);
}
以上示例演示了如何使用 ldap_next_reference() 函数遍历 LDAP 搜索操作返回的引用链。首先,我们创建一个 LDAP 连接并绑定用户。然后,执行 LDAP 搜索操作并获取第一个引用结果项。在 while 循环中,我们处理引用结果项,并使用 ldap_next_reference() 函数获取下一个引用结果项,直到没有更多的引用结果项为止。最后,我们释放搜索结果并关闭 LDAP 连接。
请注意,示例中的服务器和身份验证凭据是假设的,您需要根据实际情况进行替换。