title: Authenticating user with LDAP from PHP with only SamAccountName and Password?
body: <p>how can I authenticate from PHP using LDAP when I only have the SamAccountName and Password?  Is there a way to bind with just SamAccountName and Password and without Distinguished Name.  The only examples I have found assume you have the DN:</p>
  
  <pre><code>$server="XXX.XXX.XXX.XXX";
  $dn = "cn=$username, "; 
  $basedn="ou=users, ou=accounts, dc=domain, dc=com";
  
  if (!($connect = ldap_connect($server))) { 
     die ("Could not connect to LDAP server"); 
  } 
  
  if (!($bind = ldap_bind($connect, "$dn" . "$basedn", $password))) {        
     die ("Could not bind to $dn"); 
  } 
  
  $sr = ldap_search($connect, $basedn,"$filter"); 
  $info = ldap_get_entries($connect, $sr); 
  $fullname=$info[0]["displayname"][0]; 
  $fqdn=$info[0]["dn"]; 
  </code></pre>