Hello, I am having a problem with using LDAP and PHP... The two seperate scripts work fine, but when I try to combine them in anyway It does not complete... The scripts are below.. ldap_add.php <?php //require_once ("ldap-search-uid.php"); $dn="cn=Directory Manager"; $dn2="uid=default, ou=Users, dc=domain, dc=com"; $bindPassword = "test123"; $mySalt = substr( ereg_replace("[^a-zA-Z0-9./]","", crypt(rand(10000000,99999999), rand(10,99))), 2, 2); $password = crypt("l8rd00dZ","$mySalt");
if (($ldap = ldap_connect("ldap.server","389"))) { echo "Bind Good...\n"; } else { echo "Connection Failed...\n"; } if (($res = @ldap_bind($ldap, $dn, $bindPassword))) { $result=ldap_search($ldap,"ou=Users,dc=domain,dc=com", "uid=default") ; $info = ldap_get_entries($ldap,$result); $defaultUid = $info[0]["uidnumber"][0]; $newUid=$defaultUid+1; print "$newUid\n"; $newinfo["uidNumber"]=$newUid; ldap_modify($ldap,$dn2,$newinfo); echo "LDAP Modify successful...\n"; } else { echo "Addition Failed...\n"; } $info["loginShell"]="/bin/false"; $info["uidNumber"]="2001"; $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}testpass"; 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=domain, dc=com", $info); echo "User Added...\n"; } else { echo "Addition Failed...\n"; } ?> ldap-search.php <?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=domain, dc=com"; // 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=domain,dc=com", "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"; } else { echo "LDAP bind failed..."; } } ?> You should be able to get the idea of what I am trying to do... I have tried taking the needed pices of each script and combining them, but when I do I get an error about somehting in the info array not being correct.. Wierd thing is that it works fine when they are seperate.. Any help is greatly appreciated.. Thanks... Jim G -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php