Jump to content

ldap_mod_add() = "Value array must have consecutive indices 0, 1"


pakenney38

Recommended Posts

I am trying to use PHP to insert a contact into Windows Server 2003 Active Directory.

I do this:

 

<?PHP
$ldaprdn = 'user@test.local';
$ldappass = 'password';
$ds = 'server.test.local';
$dn = 'dc=test,dc=local';
$ldapport = 389;
$ldapconn = ldap_connect($ds, $ldapport)
or die("Could not connect to LDAP server.");

if ($ldapconn)
{
ldap_set_option($ldapconn, LDAP_OPT_PROTOCOL_VERSION,3);
ldap_set_option($ldapconn, LDAP_OPT_REFERRALS,0);
$ldapbind = ldap_bind($ldapconn, $ldaprdn, $ldappass);
if ($ldapbind)
{
echo "LDAP bind successful...";

$attr["cn"][0] = "ROSE TWILL";
$attr["objectclass"][0] = "top";
$attr["objectclass"][1] = "person";
$attr["objectclass"][2] = "organizationalPerson";
$attr["objectClass"][3] = "contact";
$attr["sn"][0] = "TWILL";
$attr["givenName"][0] = "ROSE";
$attr["displayName"][0] = "ROSE TWILL (2nd Server)";
$attr["mailNickname"][0] = "RTWILL";
$attr["targetAddress"][0] = "smtp:RTWILL@domain.com";
$attr["mail"][0] = "RTWILL@domain.com";
$attr["proxyAddresses"][0] = "smtp:RTWILL@domain.net";

$result = ldap_mod_add($ldapconn, "ou=Mail Enable,ou=Test Users,ou=Test,dc=test,dc=local", $attr);
}
else
{
echo "LDAP bind failed...";
}
}
ldap_close($ldapconn);

?>

 

I get this:

 

LDAP bind successful...
Warning: ldap_mod_add() [function.ldap-mod-add]: Value array must have consecutive indices 0, 1, ... in C:\Inetpub\wwwroot\newcontact.php on line 32

 

What does this mean and what am I doing wrong? I appreciate any help on this.

 

 

Link to comment
Share on other sites

Subsequently, if I try to run this:

 

<?PHP
$ldaprdn = 'user@test.local';
$ldappass = 'password';
$ds = 'server.test.local';
$dn = 'dc=test,dc=local';
$ldapport = 389;
$ldapconn = ldap_connect($ds, $ldapport)
or die("Could not connect to LDAP server.");

if ($ldapconn)
{
ldap_set_option($ldapconn, LDAP_OPT_PROTOCOL_VERSION,3);
ldap_set_option($ldapconn, LDAP_OPT_REFERRALS,0);
$ldapbind = ldap_bind($ldapconn, $ldaprdn, $ldappass);
if ($ldapbind)
{
echo "LDAP bind successful...";

$attr["cn"] = "ROSE TWILL";
$attr["objectClass"] = "contact";
$attr["sn"] = "TWILL";
$attr["givenName"] = "ROSE";
$attr["displayName"] = "ROSE TWILL (2nd Server)";
$attr["mailNickname"] = "RTWILL";
$attr["targetAddress"] = "smtp:RTWILL@domain.com";
$attr["mail"] = "RTWILL@domain.com";
$attr["proxyAddresses"] = "smtp:RTWILL@domain.net";

$result = ldap_mod_add($ldapconn, "ou=Mail Enable,ou=Test Users,ou=Test,dc=test,dc=local", $attr);
}
else
{
echo "LDAP bind failed...";
}
}
ldap_close($ldapconn);

?>

 

I get back:

 

LDAP bind successful...
Warning: ldap_mod_add() [function:ldap-mod-add]: Modify: Server is unwilling to perform in C:\Intepub\wwwroot\newcontact.php on line 29

 

What so now Active Directory is just telling me "no" ?

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.