Php 警告:ldap_modify():修改:服务器不愿意执行

Php 警告:ldap_modify():修改:服务器不愿意执行,php,ldap,Php,Ldap,在这里,我真的很难实现Active Directory和PHP之间的集成。我试图更新的字段有:givenname、sn、mail、telephonenumber、company、department和title。它给了我以下错误: Warning: ldap_modify(): Modify: Server is unwilling to perform in E:\IIS^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 通过搜索internet,我发

在这里,我真的很难实现Active Directory和PHP之间的集成。我试图更新的字段有:givenname、sn、mail、telephonenumber、company、department和title。它给了我以下错误:

Warning: ldap_modify(): Modify: Server is unwilling to perform in E:\IIS^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
通过搜索internet,我发现我必须使用LDAPS而不是LDAP,但我不知道这里出了什么问题:

function get_active_directory_info($username, $password)
{
    $conn         = ldap_connect("DC-1");
    if($conn==FALSE)
    {
        return array(FALSE, FALSE);
    }
    else
    {
        $bind = ldap_bind($conn, $username, $password);
        ldap_set_option($conn, LDAP_OPT_PROTOCOL_VERSION,3);
        ldap_set_option($conn, LDAP_OPT_REFERRALS,0);
        $unit         = "OU=Staff,OU=Users,DC=example,DC=internal";
        $filter         = "(&(objectCategory=person)(sAMAccountName=*)(!(UserAccountControl=514)))";
        $results        = array();
        $justthese     = array("sn", "givenname", "mail", "company","department","title","telephonenumber","samaccountname", "cn");
        $sr=ldap_search($conn, $unit, $filter, $justthese);
        $info = ldap_get_entries($conn, $sr);        
        for($i = 0; $i < $info["count"]; $i++)
        {
            $cn = $info[$i]["cn"][0];
            if(substr($cn, -3) != "ADM")
            {
                $results[$i]["id"] = $i + 1;
                if(empty($info[$i]["givenname"][0])==FALSE)
                {
                    $results[$i]["first"] = $info[$i]["givenname"][0];
                }
                if(empty($info[$i]["sn"][0])==FALSE)
                {
                    $results[$i]["last"] = $info[$i]["sn"][0];
                }
                if(empty($info[$i]["mail"][0])==FALSE)
                {
                    $results[$i]["email"] = $info[$i]["mail"][0];
                }    
                if(empty($info[$i]["company"][0])==FALSE)
                {
                    $results[$i]["company"] = $info[$i]["company"][0];
                }
                if(empty($info[$i]["title"][0])==FALSE)
                {
                    $results[$i]["title"] = $info[$i]["title"][0];
                }    
                if(empty($info[$i]["department"][0])==FALSE)
                {
                    $results[$i]["department"] = $info[$i]["department"][0];
                }    
                if(empty($info[$i]["telephonenumber"][0])==FALSE)
                {
                    $results[$i]["number"] = $info[$i]["telephonenumber"][0];
                }    
                if(empty($info[$i]["samaccountname"][0])==FALSE)
                {
                    $results[$i]["username"] = $info[$i]["samaccountname"][0];
                }
            }
        }
    }    
    return $results;    
}  
函数获取活动目录信息($username,$password)
{
$conn=ldap_连接(“DC-1”);
如果($conn==FALSE)
{
返回数组(FALSE,FALSE);
}
其他的
{
$bind=ldap_bind($conn、$username、$password);
ldap_设置_选项($conn,ldap_选项_协议_版本,3);
ldap\u set\u选项($conn,ldap\u OPT\u references,0);
$unit=“OU=员工,OU=用户,DC=示例,DC=内部”;
$filter=“(&(objectCategory=person)(sAMAccountName=*)(!(UserAccountControl=514))”;
$results=array();
$justThises=数组(“序列号”、“给定名称”、“邮件”、“公司”、“部门”、“标题”、“电话号码”、“samaccountname”、“cn”);
$sr=ldap\u搜索($conn,$unit,$filter,$justthis);
$info=ldap\u get\u条目($conn,$sr);
对于($i=0;$i<$info[“计数”];$i++)
{
$cn=$info[$i][“cn”][0];
if(substr($cn,-3)!=“ADM”)
{
$results[$i][“id”]=$i+1;
if(空($info[$i][“givenname”][0])==FALSE)
{
$results[$i][“first”]=$info[$i][“givenname”][0];
}
if(空($info[$i][“sn”][0])==FALSE)
{
$results[$i][“last”]=$info[$i][“sn”][0];
}
if(空($info[$i][“邮件”][0])==FALSE)
{
$results[$i][“email”]=$info[$i][“mail”][0];
}    
if(空($info[$i][“公司”][0])==FALSE)
{
$results[$i][“company”]=$info[$i][“company”][0];
}
if(空($info[$i][“title”][0])==FALSE)
{
$results[$i][“title”]=$info[$i][“title”][0];
}    
if(空($info[$i][“部门”][0])==FALSE)
{
$results[$i][“department”]=$info[$i][“department”][0];
}    
if(空($info[$i][“电话号码”][0])==FALSE)
{
$results[$i][“number”]=$info[$i][“telephonenumber”][0];
}    
if(空($info[$i][“samaccountname”][0])==FALSE)
{
$results[$i][“username”]=$info[$i][“samaccountname”][0];
}
}
}
}    
返回$results;
}  

如果我没记错,您需要LDAP来更改密码,我看您没有这样做。您是否也尝试过一个更简单的例子,只是为了尝试一下它是否有效

我已经用您提供的信息更改了以下代码,但您应该更改主机、用户名和密码。当你尝试这个时会发生什么

$r=ldap_bind($ds, "username", "password");

$ldapconn = ldap_connect("LDAP://HOST:389");

if ($ldapconn) {

    // binding to ldap server
    $ldapbind = ldap_bind($ldapconn, "username", "password");

    $justthese = array("otherTelephone");

    $search = ldap_search($ldapconn,"OU=Staff,OU=Users,DC=example,DC=internal", "(&(objectCategory=person)(sAMAccountName=*)(!(UserAccountControl=514)))", $justthese);

    $entry = ldap_get_entries($ldapconn, $search);

    $dn=$entry[0]["dn"];

    $userdata=array();
    $userdata["otherTelephone"][0]= "NEWPHONENUMBER";       
    ldap_modify($ldapconn, $dn, $userdata);
}   

让我知道会发生什么。

如果我没记错,您需要LDAP来更改密码,我看您没有这样做。您是否也尝试过一个更简单的例子,只是为了尝试一下它是否有效

我已经用您提供的信息更改了以下代码,但您应该更改主机、用户名和密码。当你尝试这个时会发生什么

$r=ldap_bind($ds, "username", "password");

$ldapconn = ldap_connect("LDAP://HOST:389");

if ($ldapconn) {

    // binding to ldap server
    $ldapbind = ldap_bind($ldapconn, "username", "password");

    $justthese = array("otherTelephone");

    $search = ldap_search($ldapconn,"OU=Staff,OU=Users,DC=example,DC=internal", "(&(objectCategory=person)(sAMAccountName=*)(!(UserAccountControl=514)))", $justthese);

    $entry = ldap_get_entries($ldapconn, $search);

    $dn=$entry[0]["dn"];

    $userdata=array();
    $userdata["otherTelephone"][0]= "NEWPHONENUMBER";       
    ldap_modify($ldapconn, $dn, $userdata);
}   

请告诉我发生了什么。

您必须使用LDAP加密才能

您必须使用LDAP加密才能