Subversion-Projekte lars-tiefland.php_share

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 1
<?php
2
/**
3
* This is a short example on how to fetch a specific entry in the
4
* directory using Net_LDAP2.
5
*/
6
 
7
// We use the connecting.php example to get a link to our server.
8
// This file will also include all required basic Net_LDAP2 classes.
9
include_once 'connecting.php';
10
 
11
// Okay, we should have a valid link now.
12
// Lets fetch an entry! We want to know the admins first and last name.
13
// If we need additional attributes later, we must refetch the entry.
14
// It is a good practice to only select the attributes really needed.
15
// Since we want to be a little flexible, we make the base
16
// dynamic, so it is enough to change the base-dn in your
17
// $ldap_config array.
18
$entry = $ldap->getEntry('cn=admin,'.$ldap_config['base'], array('gn', 'sn'));
19
 
20
// Error checking is important!
21
if (Net_LDAP2::isError($entry)) {
22
    die('Could not fetch entry: '.$entry->getMessage());
23
}
24
 
25
// Now fetch the data from the entry
26
$surename  = $entry->getValue('sn', 'single');
27
if (Net_LDAP2::isError($surename)) {
28
    die('Unable to get surename: '.$surename->getMessage());
29
}
30
$givenname = $entry->getValue('gn', 'single');
31
if (Net_LDAP2::isError($givenname)) {
32
    die('Unable to get surename: '.$givenname->getMessage());
33
}
34
 
35
// Finally output the data of the entry:
36
// This will give something like "Name of cn=admin,o=example,dc=org: Foo Bar"
37
echo 'Name of '.$entry->DN().': '.$givenname.' '.$surename;
38
?>