I'm currently adding some integration code to an LDAP authentication module. One of the things I need to do to finish this is to get the user's email out of the OpenLDAP server. The code connects and binds successfully, but I cannot get the mail account information I need. This is what I have:
// get base dn
global $basedn;
//get ou, using MyBB's database API
$query = $db->simple_select('settings','value','name="mybbldap_ou"');
$ou = $db->fetch_field($query, 'value');
// testing variables...
echo "<br />Base DN is $basedn<br />";
echo "<br />OU is $ou<br />";
// set up search criteria. $mybb->input['username'] is the submitted UID
$filter = "(|($ou)(uid=".$mybb->input['username']."))";
echo "<br />FILTER is $filter<br />";
$justthese = array("mail");
// run the search, $ld is the connection
$sr=ldap_search($ld,$basedn,$filter,$justthese);
if($sr==FALSE) echo "<br />SEARCH RESULTS NOT FOUND<br />";
// get the entries from the search
$entry = ldap_get_entries($ld,$sr);
if($entry==FALSE) echo "<br />ENTRIES NOT FOUND<br />";
else echo "Count of entries is ".count($entry)."<br />";
//get the values from the entry
$values = ldap_get_values($ld,$entry,"*");
if($values==FALSE) echo "<br />VALUES NOT RECEIVED<br />";
//setting the email value (hopefully)
global $LDAPmail;
$LDAPmail = $values[0];
Upon execution, the screen comes back as follows:
Base DN is dc=evolve,dc=someorg,dc=gov
OU is ou=People
FILTER is (|(ou=People)(uid=johnkurrle))
Count of entries is 3
VALUES NOT RECEIVED
The account I'm trying to access has an email account. When I use print_r() on $entry, I see my email address at $entry[1]['mail'][0]. My question is this: Am I doing something wrong, and if so, what is it?