php - Why does this LDAP query return an array with just a 0 -


i'm new ldap , active directory. i'm trying fetch email-id of authenticated user using following code. when run it, array 0 in it.

here's 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 $datapoint)     {         echo $datapoint;         echo "<hr>";     } 

this outputs 0 horizontal line below it.

the challenging thing here there no error message whatsoever , i'm not familiar ldap nor active directory.

any idea why happening.

i see several things potentially causing problems code above:

  • do mean use ldaps://? not want do. if want use encrypted connection should use ldap_start_tls , call should made after ldap_connect. purpose of testing change ldap://.
  • your $base_dn variable seems missing part of domain. should not netbios name of domain, rather qualified domain name. if domain domain.com base dn dc=domain,dc=com.
  • your search filter ($search_filter) not formed. if trying retrieve user object ldap given account name, use search filter like: (samaccountname=uid)

to better idea of may going wrong can use ldap_error , call after connect: echo "error: ".ldap_error($ldap);. can after ldap related call more information on may have gone wrong.


Comments

Popular posts from this blog

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

java - Could not locate OpenAL library -

sorting - opencl Bitonic sort with 64 bits keys -