title: How to identify different errors on ldap_bind()? PHP
body: <p>I'm using ldap_bind to connect to a Zimbra Server to authenticate users. My problem is that ldap_bind() only triggers warnings on PHP. To supress that, I'm using @. But, I would like to be able to identify weather it's a "invalid credentials" or "unable to bind server" problem.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>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');
      }
  }
  </code></pre>