title: retrieving attributes from AD with ldap search or read without knowing the Distingushed Name
body: <p>I'm trying to retrieve information(descriptionand Mail) from my active directory without knowing my DN for all the users who have logged in on my application using their domain credentials, i'm only able to retrieve the information if i provide a dn of which each dn is very different for all the users cause of the departments and Organizational Units, the binding works fine the problem is only retrieving the data specified above.</p>
  
  <p>My code is as follows..
  NB:I've changed the values of some fields.</p>
  
  <blockquote>
    <p></p>
  </blockquote>
  
  <pre><code>&lt;?php
   ldap_authenticate();
   function ldap_authenticate() {
  
   //using ldap bind
   $ldaprdn  = 'username';//ldap rdn or dn
   $ldappass = 'password';// associated password
   $filter="(&amp;(objectClass=user))";
   $justthese = array("sn","displayName");
   //connect to ldap server
   $ldapconn = ldap_connect("hostname.net");
  
   if ($ldapconn){
    //binding to ldap server
      $ldapbind = ldap_bind($ldapconn, $ldaprdn, $ldappass);
    //verify binding
      if($ldapbind){
          $dn='CN=Donald Mailula,OU=Users,OU=Group Testing,OU=Central Office,DC=hostname,DC=net';
          $sr=ldap_read($ldapconn,$dn,$filter);
          $entry = ldap_get_entries($ldapconn, $sr);
          echo $entry[0]["mail"][0] . " is the email address of the cn your requested&lt;br/&gt;";
          echo $entry[0]["description"][0];
      }else{
         echo "LDAP bind failed...";
      }
    }
  }
  
  ?&gt;
  </code></pre>
  
  <p>My main problem is that i wont be able to know the dn of all the users who logged in so i need a way to search for record without the dn, or how to get the dn first and then search for the record i need.</p>
  
  <p>Is it even possible guys?</p>
  
  <p>Please help</p>
  
  <p>Thanks
  D</p>