[PHP] Adding an LDAP account (Add: Constrain

Julien -  
immobilia Posted messages 44 Status Membre -
Hello,

When I execute this code I get this error:
Warning: ldap_add() [function.ldap-add]: Add: Constraint violation in test.php on line 56

The error is in the $adduserAD array, but I don't know where.

<? $adduserAD['cn'][0] = "PNom"; $adduserAD['sn'][0] = "NOM"; $adduserAD['mail'][0] = "prenom.nom@domaine.com"; $adduserAD['displayname'][0] = "NOM Prenom"; $adduserAD['givenname'][0] = "Prenom"; $adduserAD['name'][0] = "PNom"; $adduserAD['scriptpath'][0] = "logon.bat"; $adduserAD['userprincipalname'][0] = "PNom@DOMAINE.COM"; $adduserAD['objectclass'][0] = "top"; $adduserAD['objectclass'][1] = "person"; $adduserAD['objectclass'][2] = "organizationalPerson"; $adduserAD['objectclass'][3] = "user"; $adduserAD['userPassword'][0] = '{MD5}' . base64_encode(pack('H*',md5("pass"))); ldap_add($ds, "CN=NOM Prenom,OU=Magasin_Expedition,OU=Users,OU=101,DC=DOMAINE,DC=com", $adduserAD); ?>


Thank you in advance
Configuration: Windows XP Firefox 2.0.0.5

7 réponses

Julien
 
Thank you for your responses Alain42, it's very nice of you, but <?php or <? won't change anything for me, because the functions I use are from PHP 4.

As for the LDAP path, it's good, because I can see all the information on all the accounts.....etc.

Because in this Active Directory, the hierarchy is only classified by OUs (it's not me who did that, lol).
1
Alain42
 
If you are using PHP5, avoid using short tags <? ?> and use <?php ?> instead.

Then, I don't know this function, but is it normal that you have multiple ORs?

Looking at the site manuelphp.com, it seems that you should use the same parameters as those for the LDAP connection.
0
Alain42
 
I don't know if it will be helpful to you, but I just found an interesting tutorial on LDAP:

https://www.developpez.com/telechargements/auth/id/43205ff6537108d65199ece96809fb2b
0
Julien
 
lol, I've already gone through all the resources possible to find on Google.

PHP 5 is not the point I'm interested in, especially since it's a test script.

No LDAP expert around??????????
0
Julien
 
my 2 LDAP paths are correct (tested).
0
Alain42
 
I'm sorry to insist, but you need to use standardized tags <?php ?> because even for a test script, it must run on a platform with a version of PHP. And if it's on php5, you might encounter weird behaviors; I've had the problem before, and while browsing the forum, I found out I'm not the only one!

I'm not an LDAP specialist, but it seems strange to me that you have multiple OUs (that would mean you're adding to several entries on your LDAP server). The tutorial I pointed out to you looks pretty good; I know you've read some before, but take a look at it anyway.
-1
immobilia Posted messages 44 Status Membre 17
 
Your answer can be found at LDAP PHP.

It just happens that your 'scriptpath' and 'userprincipalname' attributes are not defined in the standard classes.
If the 'user' class is one of your personal classes, make sure it is included in the schema reading and that it allows these 2 attributes.

P.S. for Alain42: the tags <?php have nothing to do in this context; if there is a PHP return, it means he is using what is needed in relation to the server <? or <?php.
-1