problem in using ldap_add() function

From: Date: Tue, 06 Mar 2007 07:50:49 +0000
Subject: problem in using ldap_add() function
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-249914@lists.php.net to get a copy of this message
Hi , i m trying to insert a new user account into the ldap using php . bt i m getting the following warning and the data is not geting inserted _____________________________________________________ Warning: ldap_add() [function.ldap-add]: Value array must have consecutive indices 0, 1, ... in /home/arun/public_html/globees_webservice/Authentication_Layer/cls.authentication.php on line 148 Could not add new entry! ______________________________________________________ following is my ldap details _______________________________________________ openldap2.2 LDPv3 PHP Version 5.1.2 Server: Ubuntu 6.06.1 LTS Apache2 the ldap is working queit fine with other systems. ________________________________________________________ here i am also inclding the code i was trying .... ____________________________________________________________________________ function addUser($username,$password){
           $dn   = "uid=arun,ou=People,dc=globees,dc=com";
           $pass = 'arun';
           $ds=ldap_connect('localhost');  // must be a valid LDAP server!
           $session_id     = '';
           $error_status   = '-';
            if ($ds) {
                 if (!ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3))
                       $error_status =  "Failed to set protocol version 3";
                 $r=@ldap_bind($ds,$dn,$pass);
                 if ($r == TRUE)
                 {
                       ////
                       //do insertion
                       $dn   = "uid=testarun,ou=People,dc=globees,dc=com";
                       $entry["uid"] = "testarun";
                       $entry["cn"]  = "testarun";
                       $entry["sn"]  = "test";
                       $entry['mail'] = "arun@globees.com";
                       $entry['objectClass'][0] = "inetLocalMailRecipient";
                        $entry['objectclass'][1] = "person";
                       $entry['objectclass'][2] = "organizationalPerson";
                       $entry['objectclass'][3] = "inetOrgPerson";
                       $entry['objectClass'][4] = "posixAccount";
                       $entry['objectClass'][5] = "top";
                       $entry['objectClass'][6] = "shadowAccount";
                       $entry["gidnumber"]  = 100;
                       $entry['homeDirectory'] = "/home/arun";
                       $entry['gecos'] = "testarun";
                       $entry['loginShell']= '/bin/bash';
                       $entry['userPassword']='{MD5}' .
base64_encode(pack('H*',md5("testarun")));
                        $f = ldap_add($ds, $dn, $entry) or die("Could
not add new entry!");
                       if($f==TRUE)  //return a success mesage if
insertion successful
                            echo "successfully added";
                       ////////////////////
                 }
                 elseif ($r == FALSE)
                    $error_status =  "Access Denied!!!";
                 else
                    $error_status =   "LDAP ERROR!";
               }
             else
                  $error_status =      "Connection Error";
          return $error_status;
       }//end of method
_________________________________________________________________________ if anybody has some possible solutions to solve this problem plzz.... give me a reply -- Regards, ...Arun

« previous php.general (#249914) next »