pakenney38 Posted April 4, 2008 Share Posted April 4, 2008 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. Quote Link to comment Share on other sites More sharing options...
pakenney38 Posted April 4, 2008 Author Share Posted April 4, 2008 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" ? Quote Link to comment Share on other sites More sharing options...
pakenney38 Posted April 4, 2008 Author Share Posted April 4, 2008 Apparently I got some incorrect documentation. The command I am supposed to be using is ldap_add(), not ldap_mod_add(). Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.