Indeed I am frustrated with LDAP connectivity in my PHP situation, however, I'm reallllly close here so I'm still smiling at least.
Here's what I've got -
PHP connection to LDAP (Windows 2003 AD). I've created an intranet form that creates user accounts.
The connection is made, it's bound to AD. I've corrected (I think) the issues with invalid AD variables. Now I'm getting an error...
Warning: ldap_add() [function.ldap-add]: Add: Already exists on Line...
I think this stems somewhere from the objectclass variable, but I need this to be classified as a User (Because it is a user). I've tried changing it to other things (inetorgperson, person, etc.) but to no avail. Any ideas? Is there an AD variahble that I need that may be missing? Code is posted below.
$ou = "ou=...thirdou..., ou=...secondou..., ou=...firstou..., dc=...domain...";
$adduserAD["cn"][0] = $_POST['firstname'];
$adduserAD["samaccountname"][0] = $_POST['lastname'] . '.' . $_POST['firstname'];
$adduserAD["objectclass"] = "User";
$adduserAD["displayname"][0] = $_POST['firstname'] . ' ' . $_POST['lastname'];
$adduserAD["sn"][0] = $_POST['lastname'];
$adduserAD["description"][0] = $_POST['class'];
$adduserAD["uid"][0] = $_POST['lastname'] . '.' . $_POST['firstname'];
$adduserAD["userpassword"][0] = $_POST['password'];
$adduserAD["userAccountControl"][0] = "544";
// Connect to LDAP Server
if (!($ldap = ldap_connect("ldap://ldap.springboro.internal"))) {
die ("Could not connect to LDAP server");
}
// Bind to LDAP and Active Directory
if (!($res = ldap_bind($ldap, "...username...", "...password..."))) {
die ("Could not bind to the LDAP account");
}
// Add the information from the form
if (!(ldap_add($ldap, $ou, $adduserAD))) {
echo "There was a problem creating the account.";
echo "Please contact your administrator!";
exit;
} else {
echo "The account for " . $_POST['firstname'] . " " . $_POST['lastname'] . " was created succcessfully.";
echo "The password for this account is " . $_POST['password'] . ".";
exit;
}
ldap_unbind($ldap);
}