1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
| $server = "monIP";
$port = "monPort";
$ldapdn="uid=diradmin,cn=users,dc=mon,dc=serveur,dc=com";
$ldappassword = 'monPassword';
//Connexion
$ldapconn = ldap_connect($server, $port);
ldap_set_option($ldapconn, LDAP_OPT_PROTOCOL_VERSION, 3);
//Liaison
if($ldapconn == 1){
$ldapbind= ldap_bind($ldapconn, $ldapdn, $ldappassword);
if($ldapbind){
//Ajout
$newUser['objectClass'][0]= 'inetOrgPerson';
$newUser['objectClass'][1]= 'posixAccount';
$newUser['objectClass'][2]= 'shadowAccount';
$newUser['objectClass'][3]= 'apple-user';
$newUser['objectClass'][4]= 'extensibleObject';
$newUser['objectClass'][5]= 'organizationalPerson';
$newUser['objectClass'][6]= 'top';
$newUser['objectClass'][7]= 'person';
$newUser['uid']= 'test';
$newUser['altSecurityIdentities']= 'Kerberos:test@MON.SERVEUR.COM';
$newUser['userPassword']= 'test';
$newUser['givenName']= 'Test';
$newUser['cn']= 'test';
if(!ldap_add($ldapconn, "uid=test,cn=users,dc=mon,dc=serveur,dc=com", $newUser)){
echo '<h3>Echec de l\'ajout du nouvel utilisateur.</h3>';
}
ldap_unbind($ldapconn);
}
else{
echo "<h3>Echec du bind.</h3>";
}
}
else{
echo '<h3>Echec de connexion au serveur.</h3>';
}
ldap_close($ldapconn); |
Partager