note 59977 added to function.ldap-read

From: Date: Wed, 21 Dec 2005 19:21:17 +0000
Subject: note 59977 added to function.ldap-read
Groups: php.notes 
Request: Send a blank email to php-notes+get-100527@lists.php.net to get a copy of this message
Clarification of the ldap_read command syntax: If you just want to pull certain attributes from an object and you already know it's dn, the ldap_read command can do this as illustrated below. It will be less overhead than ldap_search. The string base_dn which is normally used to set the top context for a recursive ldap_search is used slightly differently with this command. It is used to specify the actual object with the full dn. (Hopefully this saves someone else a couple hours trying this command out.) <?php $ds = ldap.myserver.com // your ldap server $dn = "cn=username,o=My Company, c=US"; //the object itself instead of the top search level as in ldap_search $filter="(objectclass=*)"; // this command requires some filter $justthese = array("ou", "sn", "givenname", "mail"); //the attributes to pull, which is much more efficient than pulling all attributes if you don't do this $sr=ldap_read($ds, $dn, $filter, $justthese); $entry = ldap_get_entries($ds, $sr); echo $entry[0]["mail"][0] . "is the email address of the cn your requested"; echo $entry[0]["sn"][0] . "is the sn of the cn your requested"; ldap_close($ds); ?> This prints out the specified users mail and surname for example. ---- Manual Page -- http://www.php.net/manual/en/function.ldap-read.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+59977 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+59977&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+59977&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+59977&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+59977&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+59977&report=yes&reason=non-english Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+59977&report=yes&reason=already+in+docs Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+59977&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+59977&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#100527) next »