我使用ldap_bind连接到Zimbra服务器以验证用户身份。我的问题是ldap_bind()只在PHP上触发警告。为了压制它,我使用@。但是,我希望能够识别天气,这是一个无效的凭证"或"无法绑定服务器"问题
这是我的代码:
private function ldap($email, $password) {
$login = explode('@', $email);
$name = $login[0];
$domain = str_replace('.', ',dc=', $login[1]);
$dn = 'uid=' . $name . ',ou=people,dc=' . $domain;
$ldap['user'] = $name;
$ldap['pass'] = $password;
$ldap['host'] = 'webmail.' . $login[1];
$ldap['port'] = 389;
$ldap['dn'] = $dn;
$ldap['base'] = '';
$ldap['conn'] = ldap_connect($ldap['host'], $ldap['port']);
ldap_set_option($ldap['conn'], LDAP_OPT_PROTOCOL_VERSION, 3);
// This will cause a notice error level, which cannot be catched. Supress the error and validate afterwards.
$ldap['bind'] = @ldap_bind($ldap['conn'], $ldap['dn'], $ldap['pass']);
if ($ldap['bind']) {
return true;
} else {
throw new NavException('controller.usuario.ldap.password');
}
}