函式名: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 連線。
請注意,示例中的伺服器和身份驗證憑據是假設的,您需要根據實際情況進行替換。