开发者

LDAP_add with PHP: Operations Error

开发者 https://www.devze.com 2023-03-06 07:46 出处:网络
I am quite a noob in using LDAP (this is actually my first project) and I can\'t find an answer on google that can help me...

I am quite a noob in using LDAP (this is actually my first project) and I can't find an answer on google that can help me... So my problem is: I'm trying to add a contact with php to an active directory on a windows 2003 server. I can connect to the server, and neither I have problems with ldap_bind. But when I run the program I always get the Error:

Warning: ldap_add() [function.ldap-add]: Add: Operations error in (Blabla) on line bla

and the ldap_error also only says "Operations error" which is pretty vague, so I don't even know if it's a problem with the server or with my code. I saw some threads with similar problems where servers didn't allow anonymous access, but I even bind with an admin account and it still does not work.

My code looks a lot like this:

$ldapcon=ldap_connect("servername");

if($ldapcon) {
    $bind=ldap_bind($ldapcon,"Admin@domain.com", "somePassword");
    if($bind) {         
        //  create data...
        $info=array();
        $info["cn"][0]          = "Hans Mustermann";
        $info["sn"][0]          = "Mustermann";
        $info["givenName"][0]   = "Hans";
        $info["mail"][0]        = "MustermannH@firma.de";
        $info["objectclass"][0] = "top";
        $info["objectclass"][1] = "person";
        $info["objectclass"][2] = "organizationalPerson";
        $info["objectclass"][3] = "contact";
        $info["ou"][0]          = "Users";
        $info["ou"][1]          = "contact";

        // add Data...
 开发者_如何学C       $r=ldap_add($ldapcon, "cn=Hans Mustermann, sn=Mustermann", $info)
            or die(ldap_error($ldapcon)); //error: operations error
    }
}

Are there some infos missing? is the code wrong? do i need some changes on the ad-settings? is it a problem with "remote-rights-setting" or whatever? Am I just too stupid and blind to see the problem or is it a bigger thing that is not easy to fix? Does someone of you have an idea?

Thanks a lot Chillikarli


Instead of the or die() condition you might try this

// add Data...
if(!(ldap_add($ldapcon, "cn=Hans Mustermann, sn=Mustermann", $info))) {
     echo "There is a problem to create the account\n";
     echo "Please contact your administrator !\n";
     echo "LDAP Error: ".ldap_error($ldapcon)."\n";
     exit;
}
ldap_unbind($ldapcon);
0

精彩评论

暂无评论...
验证码 换一张
取 消