PHP.nl

ldap_modify_batch

ldap_modify_batch

Batch and execute modifications on an LDAP entry

bool **ldap_modify_batch** LDAP\Connection $ldap string $dn array $modifications_info  $controls

Modifies an existing entry in the LDAP directory. Allows detailed specification of the modifications to perform.

ldap An LDAP resource, returned by . ldap_connect

dnThe distinguished name of an LDAP entity.

modifications_info An array that specifies the modifications to make. Each entry in this array is an associative array with two or three keys: maps to the name of the attribute to modify, maps to the type of modification to perform, and (depending on the type of modification) maps to an array of attribute values relevant to the modification. attrib``modtype``values

   Possible values for  include:
   
  `modtype``LDAP_MODIFY_BATCH_ADD`
       Each value specified through  is added (as
       an additional value) to the attribute named by
       .
      `values``attrib`

LDAP_MODIFY_BATCH_REMOVE Each value specified through is removed from the attribute named by . Any value of the attribute not contained in the array will remain untouched. values``attrib``values

LDAP_MODIFY_BATCH_REMOVE_ALL All values are removed from the attribute named by . A entry must not be provided. attrib``values

LDAP_MODIFY_BATCH_REPLACE All current values of the attribute named by are replaced with the values specified through . attrib``values

   Note that any value for  must be a string, any
   value for  must be an array of strings, and
   any value for  must be one of the
   LDAP_MODIFY_BATCH_* constants listed above.
  `attrib``values``modtype`

controls Array of to send with the request. LDAP Controls

return.success

Voorbeeld: Add a telephone number to a contact

<?php
$dn = "cn=John Smith,ou=Wizards,dc=example,dc=com";
$modifs = [
    [
        "attrib"  => "telephoneNumber",
        "modtype" => LDAP_MODIFY_BATCH_ADD,
        "values"  => ["+1 555 555 1717"],
    ],
];
ldap_modify_batch($connection, $dn, $modifs);
?>

Voorbeeld: Rename a user

<?php
$dn = "cn=John Smith,ou=Wizards,dc=example,dc=com";
$modifs = [
    [
        "attrib"  => "sn",
        "modtype" => LDAP_MODIFY_BATCH_REPLACE,
        "values"  => ["Smith-Jones"],
    ],
    [
        "attrib"  => "givenName",
        "modtype" => LDAP_MODIFY_BATCH_REPLACE,
        "values"  => ["Jack"],
    ],
];
ldap_modify_batch($connection, $dn, $modifs);
ldap_rename($connection, $dn, "cn=Jack Smith-Jones", NULL, TRUE);
?>

Voorbeeld: Add two e-mail addresses to a user

<?php
$dn = "cn=Jack Smith-Jones,ou=Wizards,dc=example,dc=com";
$modifs = [
    [
        "attrib"  => "mail",
        "modtype" => LDAP_MODIFY_BATCH_ADD,
        "values"  => [
            "jack.smith@example.com",
            "jack.smith-jones@example.com",
        ],
    ],
];
ldap_modify_batch($connection, $dn, $modifs);
?>

Voorbeeld: Change a user's password

<?php
$dn = "cn=Jack Smith-Jones,ou=Wizards,dc=example,dc=com";
$modifs = [
    [
        "attrib"  => "userPassword",
        "modtype" => LDAP_MODIFY_BATCH_REMOVE,
        "values"  => ["Tr0ub4dor&3"],
    ],
    [
        "attrib"  => "userPassword",
        "modtype" => LDAP_MODIFY_BATCH_ADD,
        "values"  => ["correct horse battery staple"],
    ],
];
ldap_modify_batch($connection, $dn, $modifs);
?>

Voorbeeld: Change a user's password (Active Directory)

<?php
function adifyPw($pw)
{
    return iconv("UTF-8", "UTF-16LE", '"' . $pw . '"');
}

$dn = "cn=Jack Smith-Jones,ou=Wizards,dc=ad,dc=example,dc=com";
$modifs = [
    [
        "attrib"  => "unicodePwd",
        "modtype" => LDAP_MODIFY_BATCH_REMOVE,
        "values"  => [adifyPw("Tr0ub4dor&3")],
    ],
    [
        "attrib"  => "unicodePwd",
        "modtype" => LDAP_MODIFY_BATCH_ADD,
        "values"  => [adifyPw("correct horse battery staple")],
    ],
];
ldap_modify_batch($connection, $dn, $modifs);