- <?php
- Phpinfo ();
- $host = "******:389";
- $user = "**@**";
- $PSWD = "* * *";
- $ad = Ldap_connect ($host) or die ("could not connect!");
- if ($ad) {
- Setting parameters
- Ldap_set_option ($ad, Ldap_opt_protocol_version, 3);
- Ldap_set_option ($ad, ldap_opt_referrals, 0);
- BOOL Ldap_bind (Resource $link _identifier [, string $bind _rdn = null [, string $bind _password = null]])
- $BD = Ldap_bind ($ad, $user, $pswd) or die ("Could not bind");
- echo "Ldap_bind success";
- Specify the user properties you want to get
- $attrs = Array ("displayname", "cn");
- Specify the range of users you want to query
- $filter = "(objectclass=*)";
- Ldap_search (Resource $link _identifier, String $base _dn, String $filter [, array $attributes [, int $attrsonly [, int $sizelimit [, int $timelimit [, int $deref]]]]
- $search = Ldap_search ($ad, ' dc=**,dc=**,dc=** ', $filter, $attrs, 0,0,0) or Die ("LDAP search failed");
- $entries = Ldap_get_entries ($ad, $search);
- if ($entries ["Count"] > 0) {
- Echo ' Returns the number of records: '. $entries [' count '];
- for ($i =0; $i < $entries [Count]; $i + +) {
- The field you want to get must be lowercase
- if (Isset ($entries [$i] ["displayname"])) {
- echo "<p>displayname:". $entries [$i] ["displayname"][0]. " <br/> ";//user name
- if (Isset ($entries [$i] ["cn"][0])) {
- echo "CN:". $entries [$i] ["cn"][0]. " <br/> ";//user name
- }
- }
- }
- } else {
- echo "<p>no results found!</p>";
- }
- }else{
- echo "Unable to connect to AD server";
- }
- ?>
This article links http://www.cxybl.com/html/wlbc/Php/20130319/37245.html