ldap_bind
(PHP 4, PHP 5, PHP 7, PHP 8)
ldap_bind — 繫結 LDAP 目錄
說明
   ldap_bind(resource 
  $link_identifier, string $bind_rdn = null, string $bind_password = null): bool使用指定的 RDN 和密碼繫結到 LDAP 目錄。
參數
- 
link_identifier
- 
      通過 ldap_connect() 連線之後返回的 LDAP 連線標識。 
- 
bind_rdn
- 
      
- 
bind_password
- 
      
   如果沒有指定 bind_rdn 和 bind_password ,將會以匿名身份繫結。
  
返回值
   成功時返回 true, 或者在失敗時返回 false。
  
範例
示例 #1 使用 LDAP Bind
<?php
// using ldap bind
$ldaprdn  = 'uname';     // ldap rdn or dn
$ldappass = 'password';  // associated password
// connect to ldap server
$ldapconn = ldap_connect("ldap.example.com")
    or die("Could not connect to LDAP server.");
if ($ldapconn) {
    // binding to ldap server
    $ldapbind = ldap_bind($ldapconn, $ldaprdn, $ldappass);
    // verify binding
    if ($ldapbind) {
        echo "LDAP bind successful...";
    } else {
        echo "LDAP bind failed...";
    }
}
?>
示例 #2 Using LDAP Bind Anonymously
<?php
//using ldap bind anonymously
// connect to ldap server
$ldapconn = ldap_connect("ldap.example.com")
    or die("Could not connect to LDAP server.");
if ($ldapconn) {
    // binding anonymously
    $ldapbind = ldap_bind($ldapconn);
    if ($ldapbind) {
        echo "LDAP bind anonymous successful...";
    } else {
        echo "LDAP bind anonymous failed...";
    }
}
?>