note 115446 deleted from function.ldap-add by salathe

From: Date: Mon, 04 Aug 2014 08:46:51 +0000
Subject: note 115446 deleted from function.ldap-add by salathe
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-200102@lists.php.net to get a copy of this message
Note Submitter: brandon ---- If you want to set the users password and enable the account in Active Directory this should be helpful: //Use putenv before the ldap_connect or modify /etc/ldap/ldap.conf and add "TLS_REQCERT never". Unless you have a cert (I didn't and this is what I used to make it work). putenv('LDAPTLS_REQCERT=never'); // Connection must be made using ldaps or you will receive server unwilling to perform error. $ds = ldap_connect( 'ldaps://server', '636' ); // Use protocol version 3 right after the connect ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3); // bind ldap_bind($ds, $admin_dn, $pass); // Set the info you want to set $info['cn'] = "First Last"; $info['sn'] = "Last"; $info['givenName'] = "First"; $info["displayName"] = "First Last"; // do not set the 'name' attribute, it gets set automatically $info['objectClass'][0] = "top"; $info['objectClass'][1] = "person"; $info['objectClass'][2] = "organizationalPerson"; $info['objectClass'][3] = "user"; $info["sAMAccountName"] = $first.$last; $info["userPrincipalName"] = $first.$last."@domain.local"; // Create Unicode Password $newpassword = "Password123"; $newpassword = "\"" . $newpassword . "\""; $len = strlen($newpassword); for ($i = 0; $i < $len; $i++) $newpass .= "{$newpassword{$i}}\000"; $info["unicodePwd"] = $newpass; // Enable the account $info["userAccountControl"] = "512"; // Insert into the directory ldap_add($ds, $new_user_dn, $info); // Done, user should be created, enabled and have a password.

« previous php.notes (#200102) next »