English | 简体中文 | 繁體中文
查询

ldap_sasl_bind()函数—用法及示例

「 绑定到LDAP服务器并使用SASL进行身份验证 」


函数名: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连接标识符,通过ldap_connect()函数获取。
  • $binddn(可选):绑定的DN(Distinguished Name),即用户名。
  • $password(可选):绑定的密码。
  • $sasl_mech(可选):SASL机制名称,例如"PLAIN"、"GSSAPI"等。如果未指定,则使用服务器的首选机制。
  • $sasl_realm(可选):SASL领域,用于指定要使用的领域。
  • $sasl_authc_id(可选):SASL认证ID,用于指定要用于认证的ID。
  • $sasl_authz_id(可选):SASL授权ID,用于指定要用于授权的ID。
  • $props(可选):其他SASL属性,以逗号分隔的键值对形式传递。

返回值:

  • 成功时返回true,失败时返回false。

示例:

$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'。最后根据绑定操作的结果输出相应的消息。

补充纠错
上一个函数: ldap_search()函数
下一个函数: ldap_rename()函数
热门PHP函数
分享链接