title: php LDAP Invalid credentials
body: <p>My code is:</p>
  
  <pre><code>$user = 'test';
  $password = 'testpass';
  $host = '10.1.1.1';
  $port = 389;
  $basedn = 'dc=ci,dc=mycompany,dc=com';
  $group = 'Users';
  $ldaprdn = 'uid=test,dc=ci,dc=mycompany,dc=com';
  
  $ad = ldap_connect("ldap://$host", $port);
  if ($ad) {
      echo "Connected" . "&lt;br/&gt;";
  } else {
      echo ldap_error($ad) . "&lt;br/&gt;";
  }
  ldap_set_option($ad, LDAP_OPT_PROTOCOL_VERSION, 3);
  ldap_set_option($ad, LDAP_OPT_REFERRALS, 0);
  
  //  $ldapBind = ldap_bind($ad, "{$user}@{$domain}", $password); // 1.
  //  $ldapBind = ldap_bind($ad, $user, $password); // 2.
      $ldapBind = ldap_bind($ad, $ldaprdn, $password); // 3.
  //  $ldapBind = ldap_bind($ad, null, null); // 4.
  
  if ($ldapBind) {
      echo "Binded" . "&lt;br/&gt;";
  } else {
      echo ldap_error($ad) . "&lt;br/&gt;";
  }
  </code></pre>
  
  <p>Now I use the comment line "3", get:</p>
  
  <pre><code>Connected
  Invalid credentials
  </code></pre>
  
  <p>If use the comment line "1" or "2", get:</p>
  
  <pre><code>Connected
  Invalid DN syntax
  </code></pre>
  
  <p>If use the comment line "4" (this is anonymouse), get:</p>
  
  <pre><code>Connected
  Binded
  </code></pre>
  
  <p>This is developing under Ubuntu 12.</p>
  
  <p><strong>Why I get Invalid credentials error from comment line "3"? How to bind with authentication correctly?
  Thanks in advance!</strong></p>