I'm new to LDAP and Active Directory. I'm trying to fetch the Email-ID of an authenticated user using the following code. However when I run it, all I get is an array with a 0 in it.
Here's the code
$server ='ldaps://DOMAIN';
$username = 'DOMAIN\UID';
$password = 'PASSWORD';
$base_dn = 'dc=DOMAIN';
$search_filter = 'dn=UID';
$attributes = ['mail'];
$ldap = ldap_connect($server);
ldap_set_option($ldap, LDAP_OPT_REFERRALS, 0);
ldap_set_option($ldap, LDAP_OPT_PROTOCOL_VERSION, 3);
ldap_bind($ldap, $username, $password);
$search = ldap_search($ldap, $base_dn, $search_filter, $attributes);
$data = ldap_get_entries($ldap, $search);
foreach($data as $dataPoint)
{
echo $dataPoint;
echo "<hr>";
}
This outputs just a 0 with a horizontal line below it.
The most challenging thing here is that there is no error message whatsoever and I'm not very familiar with LDAP nor with Active Directory.
Any idea as to why this could be happening.