ldap_add():添加:对象类违规错误

时间:2011-04-20 09:59:41

标签: php ldap opends

当我尝试通过PHP向OpenDS添加属性时,我收到以下错误:

  

ldap_add():添加:对象类违规

请帮忙。

这是我的代码

<?php
$ldapconfig['host'] = 'PC100';
$ldapconfig['port'] = 1389;
$ldapconfig['basedn'] = 'dc=company,dc=com';

$ds=ldap_connect($ldapconfig['host'], $ldapconfig['port']);

$password=1;
$username="cn=Directory Manager";

if ($bind=ldap_bind($ds, $username, $password)) {
  echo("Login correct");
  ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3); // IMPORTANT
  $dn = "cn=roshan1,dc=example,dc=com"; 
  //$newuser["objectclass"] = "inetOrgPerson"; 
  //$newuser["cn"] = "new1"; 
  //$newuser["sn"] = "user"; 

  $ldaprecord['cn'] = "roshan1";
  $ldaprecord['givenName'] = "mkljl";
  $ldaprecord['sn'] = "roshan";
  $ldaprecord['objectclass'] = "inetOrgPerson";    
  $ldaprecord['mail'] = "lkl@fh.com";
  $ldaprecord['mmmm'] = "77878";

  // add data to directory
  $r = ldap_add($ds, $dn, $ldaprecord);

} else {

  echo("Unable to bind to server.</br>");

}
?>

如果我从代码中删除$ldaprecord['mmmm'] = "77878";,它可以正常工作。如何添加这样的新属性?

1 个答案:

答案 0 :(得分:7)

嗯,看起来你只是想将objectclass设置为inetOrgPerson,但你必须设置inetorgPerson正在扩展的其他上层类 - 那将是{{ 1}}和top也许......

所以:

person