以下是我用来在 Active Directory 中添加用户的代码
<?php
$ldapConn = ldap_connect('ldap://xxx.xx.x.xx:389');
ldap_set_option($ldapConn, LDAP_OPT_PROTOCOL_VERSION, 3);
ldap_bind( $ldapConn, 'xx.xx@xx.xx', 'xxxx');
$dn_user='CN=testLDAP,OU=xx,DC=xx,DC=xx';
$ldaprecord['cn'] = "testLDAP";
$ldaprecord['givenName'] = "testLDAP";
$ldaprecord['sn'] = "testLDAP";
$ldaprecord['sAMAccountName'] = "testLDAP";
$ldaprecord['UserPrincipalName'] = "testLDAP@xx.xx";
$ldaprecord['displayName'] = "testLDAP";
$ldaprecord['name'] = "testLDAP";
$ldaprecord['UserAccountControl'] = "544";
$ldaprecord['objectclass'][0] = 'top';
$ldaprecord['objectclass'][1] = 'person';
$ldaprecord['objectclass'][2] = 'organizationalPerson';
$ldaprecord['objectclass'][3] = 'user';
$ldaprecord['mail'] = "testLDAP@abc.com";
$add = ldap_add($ldapConn, $dn_user, $ldaprecord);
if($add) {
echo "User successfully added";
} else {
echo "User not added";
}
ldap_close($ldapConn);
?>
但我收到错误消息
警告:ldap_add() [function.ldap-add]:添加:无法联系 LDAP 服务器
我的代码有什么问题,请帮助我..提前谢谢..