Php/docs/function.ldap-bind

提供:Dev Guides
< Php
移動先:案内検索

ldap_bind

(PHP 4, PHP 5, PHP 7)

ldap_bindLDAP ディレクトリにバインドする


説明

ldap_bind ( resource $ldap [, string|null $dn = null [, string|null $password = null ]] ) : bool

指定した RDN およびパスワードを用いて LDAP ディレクトリにバインドします。


パラメータ

ldap
ldap_connect() が返す LDAP リンク ID。
dn
password

password を省略または空にした場合は匿名バインドを試みます。 匿名バインドのため、dn も空のままにできます。 これは、https://tools.ietf.org/html/rfc2251#section-4.2.2 で定義されています。


返り値

成功した場合に true を、失敗した場合に false を返します。


例1 LDAP バインドの使用

<?php// ldap バインドを使用する$ldaprdn  = 'uname';     // ldap rdn あるいは dn$ldappass = 'password';  // パスワード// ldap サーバーに接続する$ldapconn = ldap_connect("ldap.example.com")    or die("Could not connect to LDAP server.");if ($ldapconn) {    // ldap サーバーにバインドする    $ldapbind = ldap_bind($ldapconn, $ldaprdn, $ldappass);    // バインド結果を検証する    if ($ldapbind) {        echo "LDAP bind successful...";    } else {        echo "LDAP bind failed...";    }}?>

例2 LDAP 匿名バインドの使用

<?php// ldap 匿名バインドを使用する// ldap サーバーに接続する$ldapconn = ldap_connect("ldap.example.com")    or die("Could not connect to LDAP server.");if ($ldapconn) {    // 匿名でバインドする    $ldapbind = ldap_bind($ldapconn);    if ($ldapbind) {        echo "LDAP bind anonymous successful...";    } else {        echo "LDAP bind anonymous failed...";    }}?>

参考

  • ldap_unbind() - LDAP ディレクトリへのバインドを解除する