函数名:ldap_sasl_bind()
适用版本:PHP 5 >= 5.1.0, PHP 7, PHP 8
用法: ldap_sasl_bind(resource $ldap, ?string $binddn = null, ?string $password = null, ?string $sasl_mech = null, ?string $sasl_realm = null, ?string $sasl_authc_id = null, ?string $sasl_authz_id = null, ?string $props = null): bool
该函数用于绑定到LDAP服务器并使用SASL进行身份验证。SASL(Simple Authentication and Security Layer)是一种用于身份验证和安全性的标准框架。
参数:
返回值:
示例:
$ldap = ldap_connect('ldap.example.com');
ldap_set_option($ldap, LDAP_OPT_PROTOCOL_VERSION, 3);
if (ldap_sasl_bind($ldap, 'cn=admin,dc=example,dc=com', 'password', 'PLAIN')) {
echo "LDAP bind successful";
} else {
echo "LDAP bind failed";
}
以上示例中,我们首先使用ldap_connect()函数建立与LDAP服务器的连接。然后,使用ldap_set_option()函数设置LDAP连接的协议版本为3。接下来,我们使用ldap_sasl_bind()函数进行绑定操作。指定了绑定的DN('cn=admin,dc=example,dc=com')和密码('password'),并指定了SASL机制为'PLAIN'。最后根据绑定操作的结果输出相应的消息。