PHP Access LDAP

Source: Internet
Author: User
Tags ldap
/** * @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; }
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.