note 115446 added to function.ldap-add

From: Date: Wed, 23 Jul 2014 22:47:08 +0000
Subject: note 115446 added to function.ldap-add
Groups: php.notes 
Request: Send a blank email to php-notes+get-200048@lists.php.net to get a copy of this message
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. ---- Server IP: 72.52.91.14 Probable Submitter: 209.33.248.91 ---- Manual Page -- http://php.net/manual/en/function.ldap-add.php Edit -- https://master.php.net/note/edit/115446 Del: integrated -- https://master.php.net/note/delete/115446/integrated Del: useless -- https://master.php.net/note/delete/115446/useless Del: bad code -- https://master.php.net/note/delete/115446/bad+code Del: spam -- https://master.php.net/note/delete/115446/spam Del: non-english -- https://master.php.net/note/delete/115446/non-english Del: in docs -- https://master.php.net/note/delete/115446/in+docs Del: other reasons-- https://master.php.net/note/delete/115446 Reject -- https://master.php.net/note/reject/115446 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#200048) next »