![]() Communications Software |
||||
| Plexcel for PHP - Active Directory PHP Integration | ||||
| plexcel_new plexcel_status plexcel_find_authorities_by_domain plexcel_get_authority plexcel_get_domain plexcel_log plexcel_preamble plexcel_authenticate plexcel_sso plexcel_logon plexcel_logoff plexcel_accept_token plexcel_is_member_of plexcel_set_password plexcel_change_password plexcel_gen_service_keytab plexcel_search_objects plexcel_get_account plexcel_add_object plexcel_modify_object plexcel_delete_object plexcel_set_attrdefs plexcel_get_attrdefs plexcel_set_conv_attrdefs |
Synopsisbool plexcel_add_object(resource $px, array $obj, array $attrs) DescriptionThe plexcel_add_object function adds an object to the directory. The $px parameter is the Plexcel context resource representing the directory binding and context specific options. The $obj parameter is an array of attributes representing the object being added to the directory. The distinguishedName attribute in this parameter is used to address the object being created and must be present. The $attrs parameter is an array of attribute names indicating the attributes in the $obj array that should be created. If the $attrs parameter is NULL , all attributes in $obj will be created when the object is added to the directory. Using this parameter can make script logic simpler. Creating AccountsWhen creating accounts beware that the userAccountControl flag PLEXCEL_PASSWD_NOTREQD is required. Otherwise a PLEXCEL_LDAP_UNWILLING_TO_PERFORM error may occur. The error is caused by a password policy violation. Specifying the PLEXCEL_PASSWD_NOTREQD flag allows creating an account without the password and thus no password policy violation will occur. ReturnsThe plexcel_add_object function returns TRUE if the object was successfully added to the directory. Otherwise, FALSE is returned in which case the plexcel_status function should be consulted. ExampleThe following PHP script will create a user account using the plexcel_add_object function. <?php
session_start();
$base = 'OU=Europe,DC=example,DC=com';
$domain = 'example.com';
$username = "user@$domain";
$password = 'pass';
$givenName = 'Hans';
$sn = 'Müller';
$sAMAccountName = 'hmuller';
// always use PLEXCEL_PASSWD_NOTREQD to prevent password policy violation
$userAccountControl = PLEXCEL_NORMAL_ACCOUNT | PLEXCEL_PASSWD_NOTREQD;
$cn = "$givenName $sn";
$distinguishedName = "CN=$cn,$base";
$userPrincipalName = "$sAMAccountName@$domain";
$description = "This is $cn's description.";
$telephoneNumber = '0611/11111 0';
$px = plexcel_new(NULL, NULL);
if (plexcel_logon($px, session_id(), $username, $password) == FALSE) {
die('<pre>' . plexcel_status($px) . '</pre>');
} else {
$distinguishedName = "CN=$cn,$base";
$acct = plexcel_get_account($px, $sAMAccountName, array('sAMAccountName'));
if (is_array($acct)) {
die("An account with the name $sAMAccountName already exists: " .
$acct['distinguishedName']);
} else {
$acct = array('objectClass' => array('user'),
'distinguishedName' => $distinguishedName,
'sAMAccountName' => $sAMAccountName,
'givenName' => $givenName,
'sn' => $sn,
'userPrincipalName' => $userPrincipalName,
'description' => array($description),
'telephoneNumber' => $telephoneNumber,
'userAccountControl' => $userAccountControl);
if (plexcel_add_object($px, $acct, NULL) == FALSE) {
die('<pre>' . plexcel_status($px) . '</pre>');
} else {
echo 'The account was created successfully.';
}
}
}
?>
Adding a user to the directory using plexcel_add_object
See alsoplexcel_modify_object | plexcel_delete_object | plexcel_search_objects | plexcel_get_account |
|||
|
© 2008 IOPLEX Software |
Contact Us |
Policies
|