Hey everyone!
I ran into a slight problem and for the life of me I cannot figure this out. I am running Windows Server 2003 with AD installed. Everything is fine.
Here is what I got. I am trying to add a user with ldap_add function. I can get the function to work just fine! Even set all the fields that I need, there are two fields I cannot set and need help with. Now the deal with this is that the user is created just fine. Just the account is disabled, that is where the 513 thing would play a part right?
1.) I cannot set the userAccountControl field to 513 or anything for that matter. I get the error message : Warning: ldap_add(): Add: Server is unwilling to perform in C:\www\AD_IPM2\ldap.add.user.php on line 39
2.) I don't know how to set the password for the user. Is this an easy thing to do? I just want to set their password so the user is able to login right off the bat. Should be simple right?
Here is my code:
<?php
$domain_username = "50MARKETING\\smithch";
$password = "!!56chadz";
// Connects to our LDAP server.
$ldapconn = ldap_connect("192.168.1.4");
// binding to ldap server
$ldapbind = ldap_bind($ldapconn, $domain_username, $password);
// prepare data
$username = "johndoe123";
$password = "PTC99999999";
$fullname = "John Doe";
$adduserAD["cn"] = "$username";
$adduserAD["ou"] = "Marketing";
$adduserAD["telephonenumber"] = "112-299-9934";
$adduserAD["employeenumber"] = "1332323232";
$adduserAD["samaccountname"] = "$username";
$adduserAD["objectclass"] = "user";
$adduserAD["displayname"] = "$fullname";
$adduserAD["userPassword"] = "$password";
// This line below generates the unwilling to perform error. Comment out and it works fine!
$adduserAD["userAccountControl"] = "513";
$base_dn = "cn=$username,cn=Users,DC=50marketing,DC=com";
// add data to directory
echo ldap_add($ldapconn, $base_dn, $adduserAD);
ldap_close($ldapconn);
?>
If you have added a user successfully to an AD structure please help me out. I am really confused and put in a crunch. Thank you all so much and thanks for reading!
Chad R. Smith