note 26692 added to ref.ldap
| From: | jon at rack1 dot php dot net | Date: | Sat, 09 Nov 2002 04:44:05 +0000 |
| Subject: | note 26692 added to ref.ldap | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-39209@lists.php.net to get a copy of this message | ||
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];
}
--
http://www.php.net/manual/en/ref.ldap.php
http://master.php.net/manage/user-notes.php?action=edit+26692
http://master.php.net/manage/user-notes.php?action=delete+26692
http://master.php.net/manage/user-notes.php?action=reject+26692