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.
My code is as follows..
NB:I’ve changed the values of some fields.
<?php
ldap_authenticate();
function ldap_authenticate() {
//using ldap bind
$ldaprdn = 'username';//ldap rdn or dn
$ldappass = 'password';// associated password
$filter="(&(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<br/>";
echo $entry[0]["description"][0];
}else{
echo "LDAP bind failed...";
}
}
}
?>
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.
Is it even possible guys?
Please help
Thanks
D
The thing you need is called
ldap_searchyou can find a full sample here