函式名:ldap_next_attribute()
適用版本:PHP 4, PHP 5, PHP 7
函式描述:ldap_next_attribute() 函式用於獲取搜尋結果集中下一個條目的下一個屬性名。
用法: ldap_next_attribute(resource $link_identifier, resource $result_entry_identifier): string|false
引數:
- $link_identifier:LDAP 連線識別符號,透過 ldap_connect() 或 ldap_bind() 函式獲取。
- $result_entry_identifier:搜尋結果集中的一個條目識別符號,透過 ldap_first_entry() 或 ldap_next_entry() 函式獲取。
返回值:
- 成功時,返回下一個屬性名的字串。
- 如果沒有更多屬性可用,則返回 false。
示例:
<?php
// 連線 LDAP 伺服器
$ldapconn = ldap_connect("ldap.example.com") or die("無法連線到 LDAP 伺服器");
// 繫結到 LDAP 伺服器
$ldapbind = ldap_bind($ldapconn, "cn=admin,dc=example,dc=com", "password") or die("LDAP 繫結失敗");
// 搜尋條目
$ldapsearch = ldap_search($ldapconn, "dc=example,dc=com", "cn=John Doe");
// 獲取搜尋結果的第一個條目
$entry = ldap_first_entry($ldapconn, $ldapsearch);
// 獲取第一個條目的第一個屬性名
$attribute = ldap_first_attribute($ldapconn, $entry);
// 遍歷所有屬性名
while ($attribute) {
echo "屬性名: " . $attribute . "<br>";
// 獲取下一個屬性名
$attribute = ldap_next_attribute($ldapconn, $entry);
}
// 關閉 LDAP 連線
ldap_close($ldapconn);
?>
在上面的示例中,我們首先建立與 LDAP 伺服器的連線,然後繫結到伺服器。接下來,我們執行一個搜尋操作來獲取匹配條件的條目。然後,我們使用 ldap_first_entry() 函式獲取搜尋結果的第一個條目。然後,我們使用 ldap_first_attribute() 函式獲取第一個條目的第一個屬性名。使用 while 迴圈,我們遍歷所有屬性名,並將每個屬性名列印出來。最後,我們關閉 LDAP 連線。