note 26692 deleted from ref.ldap by cmb

From: Date: Sun, 17 Nov 2019 08:36:23 +0000
Subject: note 26692 deleted from ref.ldap by cmb
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-213079@lists.php.net to get a copy of this message
Note Submitter: jon dot caplinger at broadwing dot com ---- Here is an example of searching active directory in w2k. Active directory requires a user account that has permissions to search the tree. /* The following values are used for the example: 1. Domain = microsoft.com 2. Server = unstable 3. User = bgates 4. Password = iloveopensource */ // Get name value to search for from submitted form. if (isset($HTTP_GET_VARS["name"])) { $name = $HTTP_GET_VARS["name"]; } $ldap_server = "ldap://unstable.microsoft.com"; $auth_user = "bgates@microsoft.com"; $auth_pass = "iloveopensource"; // Set the base dn to search the entire microsoft.com directory. $base_dn = "DC=microsoft, DC=com"; /* filter the search for all people in the microsoft.com tree that have a name that matches any one of the following attributes name, displayname, or cn. */ $filter = "(&(objectClass=user)(objectCategory=person) (|(name=$name*)(displayname=$name*)(cn=$name*)))"; // connect to server if (!($connect=@ldap_connect($ldap))) { die("Could not connect to ldap server"); } // bind to server if (!($bind=@ldap_bind($connect, $auth_user, $auth_pass))) { die("Unable to bind to server"); } // search active directory if (!($search=@ldap_search($connect, $base_dn, $filter))) { die("Unable to search ldap server"); } $number_returned = ldap_count_entries($connect,$search); $info = ldap_get_entries($connect, $search); echo "The number of entries returned is ". $number_returned; for ($i=0; $i<$info["count"]; $i++) { echo "Name is: ". $info[$i]["name"]; echo "Display name is: ". $info[$i]["displayname"][0]; echo "Email is: ". $info[$i]["mail"][0]; echo "Telephone number is: ". $info[$i]["telephonenumber"][0]; }

« previous php.notes (#213079) next »