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 modify a specific entry in the
4
* directory using Net_LDAP2.
5
*
6
* There is an alternative way of doing this; please have a look at
7
* examples/modify_entry2.php
8
*/
9
 
10
// We use the fetch_entry.php example to get the LDAP-Entry
11
// which we will modify now.
12
include_once 'fetch_entry.php';
13
 
14
// Okay, we should have a valid Net_LDAP2_Entry object that represents
15
// a real existing entry in our directory.
16
// The changes are only locally made and executed on the server
17
// at the end of the script.
18
 
19
// What we do now is to add two new attributes, one with two values
20
// Note that we can add attribute values which we haven't selected
21
// at fetching/searching the entry - but if we do that and
22
// call getValues(), we will only see the values added and NOT all
23
// attributes present on the server!
24
$result = $entry->add(array(
25
    'mail'            => array('foo@example.org', 'test2@example.org'),
26
    'telephoneNumber' => '1234567890'
27
));
28
if (Net_LDAP2::isError($result)) {
29
    die('Unable to add attribute: '.$result->getMessage());
30
}
31
 
32
// Now we modify the first value
33
// Note, that we must give all old values, otherwise the attribute
34
// will be deleted. We specify the new absolute attribute state
35
$result = $entry->replace(array('mail' => array('test1@example.org', 'test2@example.org')));
36
if (Net_LDAP2::isError($result)) {
37
    die('Unable to modify attribute: '.$result->getMessage());
38
}
39
 
40
// And now we delete the second attribute value
41
// We must provide the old value, so the ldap server knows,
42
// which value we want to be deleted
43
$result = $entry->delete(array('mail' => 'test2@example.org'));
44
if (Net_LDAP2::isError($result)) {
45
    die('Unable to delete attribute value: '.$result->getMessage());
46
}
47
 
48
// Finally, we delete the whole attribute 'telephoneNumber':
49
$result = $entry->delete('telephoneNumber');
50
if (Net_LDAP2::isError($result)) {
51
    die('Unable to delete attribute: '.$result->getMessage());
52
}
53
 
54
// Now it is time to transfer the changes to the ldap
55
// directory. However, for security reasons, this line is
56
// commented out.
57
 
58
/*
59
$result = $entry->update();
60
if (Net_LDAP2::isError($result)) {
61
    die('Unable to update entry: '.$result->getMessage());
62
}
63
*/
64
?>