title: PHP ldap_bind() authentication - error Unable to bind to server: Invalid credentials?
body: <p>I'm trying to authenticate a user with LDAP using PHP.  I have the DN for the user which I have checked to be correct.  I also have a password.  This is the correct password for the user when they authenticate with <code>SamAccountName</code>.  </p>
  
  <p>I am hoping this is the password to use when authenticating with the DN.  There isn't a Distinguished Name specific password for LDAP is there?   The following is my code to authenticate using PHP's <code>ldap_bind()</code> function.  Am I doing this correct? </p>
  
  <pre><code>$ldaphost="ldap://somehost.com:3268";
  $dn = "cn=LastName\, FirstName Dept/Country/ext,OU=Accounts,OU=Location,ou=Division,";
  $basedn="dc=abc,dc=enterprise";
  
  if (!($connect = ldap_connect($ldaphost))) {    
    die ("Could not connect to LDAP server"); 
  } 
  
  $ldapbind = ldap_bind($connect, "$dn" . "$basedn", $password);
  
  if ($ldapbind) {
     echo "LDAP bind successful...";
  } else {
     echo "LDAP bind failed...";
  }
  </code></pre>
  
  <p>The result I get from the above code is :</p>
  
  <blockquote>
    <p>Warning: ldap_bind() [function.ldap-bind]: Unable to bind to server:
    Invalid credentials LDAP bind failed...</p>
  </blockquote>
  
  <p>From the line where <code>ldap_bind()</code> call is made:</p>
  
  <pre><code>$ldapbind = ldap_bind($connect, "$dn" . "$basedn", $password);
  </code></pre>
  
  <p>Invalid credentials makes me believe there is something wrong potentially with the DN or password.  I have triple checked the DN and there is not an error there as far as I can see.</p>
  
  <p>Any ideas?</p>