title: Get SamAccountname from LDAP using PHP
body: <p>Ldap Authentication works. I just want to get the samaccountname from Ldap using php.  I can get the users email, and OU and display name, but is there a way to get the SamAccountName?</p>
  
  <p>I'm using this:</p>
  
  <pre><code>if (@!$loginldap = ldap_bind($ds, "$username@$ldap_domain", $password)) { 
    if ($loginldap) { // if binding to ldap works
     $attributes = array("displayname", "mail");
     $filter = "(&amp;(objectCategory=person)(sAMAccountName=$username))";
     $result = ldap_search($ds, $ldap_dn, $filter, $attributes);
     $entries = ldap_get_entries($ds, $result);
    }
  }
  </code></pre>
  
  <p>and the $entries array contains all the stuff I need except for SamAccountName. </p>
  
  <p>Thanks.</p>