On Aug 22, 2011, at 3:18 PM, Jacob Beauregard wrote:
> I want to better understand how data comes out of UVM's LDAP server.
>
> The return format of PHP's ldap_get_entries function contains an array for every LDAP attribute that comes out of the server. I would like to learn, based on the schemas in use, whether I can expect a single value in any given field as opposed to the possibility of multiple values. E.g. I would expect only one dn. I would also like to learn what other assumptions I can make of the data.
I have found everything I ever needed to know about LDAP with these lines of code, especially the print_r and is_array bits.
$ldapserver ="ldaps://ldap.uvm.edu" ;
$dnstring ="ou=People,dc=uvm,dc=edu" ;
$filter ="(uid=$_POST['uid'])" ;
$ds =ldap_connect ($ldapserver );
if ( $ds ) {
// this is an anonymous bind - just to search
$r =ldap_bind ($ds);
//perform the search
$sr =ldap_search ($ds ,$dnstring ,$filter);
//if we couldn't find them, return false
if(! ldap_count_entries ($ds ,$sr )) {
print "No user {$_SERVER['REMOTE_USER']}" ;
exit;
}
//retrieve records found by the search
$info =ldap_get_entries ($ds ,$sr );
print "<pre>\n";
// This tells you everything you need to know...
print_r($info);
print "\n\n";
foreach ($info[0] as $entry) {
if (!is_array($entry)) {
// single attribute
print "LDAP field name for above: $entry\n\n";
} else {
// multiple attributes
foreach($entry as $index=>$subfield) {
print "entry $index : $subfield\n";
}
}
}
ldap_close ($ds );
}
-----------------------------------------------------------------------
| Wesley Alan Wright <mailto:[log in to unmask]> |
| Center for Teaching and Learning __0__ |
| Room 407 Lafayette Building / \ | \ |
| University of Vermont \77 |
| Burlington, Vermont 05405-0160 USA. \\ http://www.uvm.edu/skivt-l |
| Voice: 802-656-1254 vv |
| aim:goim?screenname=maddogskideath http://www.uvm.edu/~waw/ |
-----------------------------------------------------------------------
|