PHP gets AD domain User: Php reads AD user

Source: Internet
Author: User
Tags filter array bind count connect resource domain ad server
 
 
  1. <?php
  2. Phpinfo ();
  3. $host = "******:389";
  4. $user = "**@**";
  5. $PSWD = "* * *";
  6. $ad = Ldap_connect ($host) or die ("could not connect!");
  7. if ($ad) {
  8. Setting parameters
  9. Ldap_set_option ($ad, Ldap_opt_protocol_version, 3);
  10. Ldap_set_option ($ad, ldap_opt_referrals, 0);
  11. BOOL Ldap_bind (Resource $link _identifier [, string $bind _rdn = null [, string $bind _password = null]])
  12. $BD = Ldap_bind ($ad, $user, $pswd) or die ("Could not bind");
  13. echo "Ldap_bind success";
  14. Specify the user properties you want to get
  15. $attrs = Array ("displayname", "cn");
  16. Specify the range of users you want to query
  17. $filter = "(objectclass=*)";
  18. Ldap_search (Resource $link _identifier, String $base _dn, String $filter [, array $attributes [, int $attrsonly [, int $sizelimit [, int $timelimit [, int $deref]]]]
  19. $search = Ldap_search ($ad, ' dc=**,dc=**,dc=** ', $filter, $attrs, 0,0,0) or Die ("LDAP search failed");
  20. $entries = Ldap_get_entries ($ad, $search);
  21. if ($entries ["Count"] > 0) {
  22. Echo ' Returns the number of records: '. $entries [' count '];
  23. for ($i =0; $i < $entries [Count]; $i + +) {
  24. The field you want to get must be lowercase
  25. if (Isset ($entries [$i] ["displayname"])) {
  26. echo "<p>displayname:". $entries [$i] ["displayname"][0]. " <br/> ";//user name
  27. if (Isset ($entries [$i] ["cn"][0])) {
  28. echo "CN:". $entries [$i] ["cn"][0]. " <br/> ";//user name
  29. }
  30. }
  31. }
  32. } else {
  33. echo "<p>no results found!</p>";
  34. }
  35. }else{
  36. echo "Unable to connect to AD server";
  37. }
  38. ?>
This article links http://www.cxybl.com/html/wlbc/Php/20130319/37245.html

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.