/** * @file ldap_util.php * * @author Li Yongfeng */function getuseremail ($userId) {$ldap _host = "ldap://***/"; $ldap _user = "* * *"; $ldap _pwd = "* * *"; $ldap _conn = ldap_connect ($ldap _host) or Die ("Can ' t connect to LDAP server"); Ldap_set_option ($ldap _conn, ldap_opt_referrals, 0); This is necessary ldap_set_option ($ldap _conn, ldap_opt_protocol_version, 3); This was necessary ldap_bind ($ldap _conn, $ldap _user, Base64_decode ($ldap _pwd)) or Die ("Can ' t bind to LDAP server."); $base _dn = "Dc=corpusers,dc=net"; $filter = "(Samaccountname= $userId)"; $justthese = Array ("name", "Mail"); $result = Ldap_search ($ldap _conn, $base _dn, $filter) or exit (">>unable to search LDAP server<<"); $result = Ldap_search ($ldap _conn, $base _dn, $filter, $justthese) or exit (">>unable to search LDAP server<<"); if (! $result) {echo "Ldap-errno:". Ldap_errno ($ldap _conn). "
\ n "; echo "Ldap-error:". Ldap_error ($ldap _conn). "
\ n "; Die ("argh!
\ n "); } $entry = Ldap_get_entries ($ldap _conn, $result); Ldap_unbind ($ldap _conn) or Die ("Can ' t unbind from LDAP server."); $ret = new StdClass (); if ($entry [' Count '] > 0) {$ret->name = $entry [0][' name '][0]; $ret->mail = $entry [0][' Mail '][0]; }//error_log (Json_encode ($ret)); return $ret; }