ldap_bind

(PHP 4, PHP 5, PHP 7, PHP 8)

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

説明

ldap_bind(LDAP\Connection $ldap, ?string $dn = null, ?string $password = null): bool

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

パラメータ

ldap

ldap_connect() が返す LDAP\Connection クラスのインスタンス。

dn

password

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

戻り値

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

変更履歴

バージョン 説明
8.1.0 引数 ldap は、LDAP\Connection クラスのインスタンスを期待するようになりました。 これより前のバージョンでは、有効な ldap link リソース を期待していました。

例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 ディレクトリへのバインドを解除する