ldap_modify无法正常使用PHP

时间:2018-06-20 13:30:38

标签: php ldap

我是PHP新手。我实际上是在尝试修改ldap服务器上的条目。 ldap_connect函数可以,ldap_bind也可以。

 array (size=2)
      'count' => int 1
      0 => 
        array (size=12)
          'sn' => 
            array (size=2)
              'count' => int 1
              0 => string 'Test' (length=4)
          0 => string 'sn' (length=2)
          'givenname' => 
            array (size=2)
              'count' => int 1
              0 => string 'Magasin' (length=7)
          1 => string 'givenname' (length=9)
          'uid' => 
            array (size=2)
              'count' => int 1
              0 => string 'mag-test' (length=8)
          2 => string 'uid' (length=3)
          'cn' => 
            array (size=2)
              'count' => int 1
              0 => string 'Magasin Test' (length=12)
          3 => string 'cn' (length=2)
          'employeenumber' => 
            array (size=2)
              'count' => int 1
              0 => string '00000888' (length=8)
          4 => string 'employeenumber' (length=14)
          'count' => int 5
          'dn' => string 'cn=Magasin Test,ou=Magasins,ou=AddressBook,dc=xm'

不幸的是,ldap_modify函数总是返回FALSE。以下是PHP中用于修改ldap条目的源代码。

// connexion à l'annuaire ldap
$ldapConnect = ldap_connect("ldap://".$ldapServer, $ldapPort) or die("Impossible de se connecter au serveur LDAP.<br/><br/>");
var_dump($ldapConnect);

if ($ldapConnect) {             
    $baseDnMagasins = "ou=Magasins,ou=AddressBook,dc=xm";
    $justthese = array("uid","sn","cn","givenName","mail","telephoneNumber","homephone",
        "facsimileTelephoneNumber","postalCode","postalAddress","employeeNumber",
        "businessCategory","manager","l");
    $filter = "(|(employeeNumber=*00000888*))";
    ldap_set_option($ldapConnect, LDAP_OPT_PROTOCOL_VERSION, 3);
    $ldapBind = ldap_bind($ldapConnect, $baseDnUsers, $ldapPwd);

    var_dump($ldapBind);

    if($ldapBind) {
        $sr = ldap_search($ldapConnect, $baseDnMagasins, $filter, $justthese);
        var_dump($sr);
        $info = ldap_get_entries($ldapConnect, $sr);

        var_dump($info);

        $info[0]["mail"][0] = $ret->EMAIL;
        $info[0]["mail"]["count"] = 1;
        array_push($info[0], "mail");

        $info[0]["telephoneNumber"][0] = $ret->TEL1;
        $info[0]["telephoneNumber"]["count"] = 1;
        array_push($info[0], "telephoneNumber");

        $info[0]["homePhone"][0] = $ret->TEL2;
        $info[0]["homePhone"]["count"] = 1;
        array_push($info[0], "homePhone");

        $info[0]["postalAddress"][0] = $ret->ADRESSE1." ".$ret->ADRESSE2;
        $info[0]["postalAddress"]["count"] = 1;
        array_push($info[0], "postalAddress");

        $info[0]["postalCode"][0] = $ret->CP;
        $info[0]["postalCode"]["count"] = 1;
        array_push($info[0], "postalCode");

        $info[0]["l"][0] = $ret->VILLE;
        $info[0]["l"]["count"] = 1;
        $info[0]["count"] = intval($info[0]["count"]) + 7;
        array_push($info[0], "l");

        $sqlPays = "SELECT code AS data, libelle AS label FROM polymag.pays WHERE CODE = '".$ret->CODEPAYS."'";
        $pays =& data::load('sql://mdmjson/'.$sqlPays.'?debug=0');
        $info[0]["st"][0] = $pays[0]["LABEL"];

        var_dump($info);

        $retourModifLdap = ldap_modify($ldapConnect, $baseDnMagasins, $info);
        var_dump($retourModifLdap);

        echo "ldap_error: " . ldap_error($ldapConnect);

        $info = ldap_get_entries($ldapConnect, $sr);

        var_dump($info);
        if(!$retourModifLdap) {
            $dbGenerix->db_Rollback();
            $saveOk = false;
            $erreurRetourMessage = "Erreur lors de la mise à jour du ldap.\nEnregistrement impossible du magasin!.";
        } else {
            $info = ldap_get_entries($ldapConnect, $sr);
            var_dump($info);
        }
        ldap_close ($ldapConnect); 
    } else {
        echo "Binding vers le serveur ldap non effectué!";
    }

0 个答案:

没有答案