ldap modify + add problem

From: Date: Wed, 26 Feb 2003 13:17:53 +0000
Subject: ldap modify + add problem
Groups: php.general 
Request: Send a blank email to php-general+get-137219@lists.php.net to get a copy of this message
Hello, I seem to be having a problem with doing an ldap_add and a modify in the same script. I assumed if I did an unbind after my modify I should be fine but it seems to not work still. Below is the script. 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...";
    }
} //require_once ("ldap-search-uid.php"); $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("l8rd00dZ","$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

« previous php.general (#137219) next »