Looks to me like a judiciously place $info = array(); would do wonders.

Bill

--On Wednesday, February 26, 2003 08:23:39 AM -0500 Jim Greene 
<[EMAIL PROTECTED]> wrote:

> Strange problem: Taking the 2 halfs of the scripts (the section to
> update uidNumber and the one to add the user) and combining them
> causes an error:
> Fatal error: ldap_add() [http://www.php.net/function.ldap-add]:
> Unknown attribute in the data in /home/jwgreene/ldap-add.php on line
> 68
>
> Yes doing them as 2 seperate scripts works fine. I did read something
> about not being able to do a modify, and add in the same statment, so
> I do a ldap_unbind after the completion of the first. Still does the
> same thing. Any help would be appreciated.. Thanks
>
>
> <?php
>
> // LDAP variables
> $ldaphost = "ldap.server";  // your ldap servers
> $ldapport = 389;                 // your ldap server's port number
> $ldaprdn  = "cn=Directory Manager";     // ldap rdn or dn
> $ldappass = "test123";  // associated password
> $dn2="uid=default, ou=Users, dc=megalink, dc=net";
>
> // Connecting to LDAP
> $ldapconn = ldap_connect( $ldaphost, $ldapport )
>         or die("Could not connect to LDAP server.");
>
> // connect to ldap server
>
> if ($ldapconn) {
>
>     // binding to ldap server
>     $ldapbind = ldap_bind($ldapconn, $ldaprdn, $ldappass);
>
>     // verify binding
>     if ($ldapbind) {
>         echo "LDAP bind successful...\n";
>         $result=ldap_search($ldapconn,"ou=Users,dc=megalink,dc=net",
> "u id=default");
>         $info = ldap_get_entries($ldapconn, $result);
>         $defaultUid = $info[0]["uidnumber"][0];
>         //print $defaultUid;
>         //print $info[0]["uidnumber"][0];
>         $newUid=$defaultUid+1;
>         print "$newUid\n";
>         $newinfo["uidNumber"]=$newUid;
>         ldap_modify($ldapconn,$dn2,$newinfo);
>         echo "LDAP Modify successful...\n";
>         ldap_unbind($ldapconn);
>
>     } else {
>         echo "LDAP bind failed...";
>     }
>
> }
> //Second half of script *works by itself*
> $dn="cn=Directory Manager";
> $bindPassword = "test123";
> $mySalt = substr(
> ereg_replace("[^a-zA-Z0-9./]","",
> crypt(rand(10000000,99999999), rand(10,99))),
> 2, 2);
> $password = crypt("test123","$mySalt");
>
> $info["loginShell"]="/bin/false";
> $info["uidNumber"]="1002";
> $info["gidNumber"]="100";
> $info["objectClass"][0]="posixAccount";
> $info["objectClass"][1]="top";
> $info["uid"]="test2";
> $info["gecos"]="test";
> $info["cn"]="test2";
> $info["homeDirectory"]="/home/test1";
> $info["userPassword"]="{crypt}test123";
> if (($ldap = ldap_connect("ldap.server","389"))) {
> echo "Bind Good...\n";
> }
> else {
>         echo "Connection Failed...\n";
> }
> if (($res = @ldap_bind($ldap, $dn, $bindPassword))) {
> ldap_add($ldap, "uid=test2, ou=Users, dc=megalink, dc=net", $info);
> echo "User Added...\n";
> }
> else {
>         echo "Addition Failed...\n";
> }
> ?>
>
> Jim G
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>



+----------------------------------------------------
| Bill MacAllister
| 14219 Auburn Road
| Grass Valley, CA 95949
| Phone: 530-272-8555

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to