Active directory 通过php将用户添加到Active Directory

Active directory 通过php将用户添加到Active Directory,active-directory,Active Directory,下面是我用来在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'; $ldaprec

下面是我用来在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]:add:无法联系ldap服务器

我的代码有什么问题,请帮助我。。
提前感谢。

您必须在SSL/TLS下连接才能创建用户或设置/更改密码,所有其他Active Directory功能都可以在纯文本连接下执行


为了让您的生活更轻松,我建议您查看此第三方库:

谢谢您的回复。我可以通过ldap_add()创建用户,而无需使用本地环境中的任何SSL/TLS。我已经将相同的程序上传到linux环境并执行。现在,网络为每个请求关闭,并在日志文件中获取上述异常