note 103349 added to function.ldap-mod-del
| From: | b32607 at freescale dot com | Date: | Fri, 08 Apr 2011 16:33:50 +0000 |
| Subject: | note 103349 added to function.ldap-mod-del | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-178641@lists.php.net to get a copy of this message | ||
I have been banging my head against the wall trying to use ldap_mod_del. I want to search through
the groups and then gather the group name and remove the user from those groups.
Here is my code:
$toDelete = "b15042";
$uid = "memberuid=$toDelete";
//$username['user'] =
'uid=test,ou=people,ou=cde-tx32,ou=unix-domains,dc=motorola,dc=com'; // ldap rdn or dn
$username['user'] = 'test';
$username['pass'] = 'test'; // associated password
$basedn = "'ou=people,ou=unix-domains,dc=domain,dc=com";
// Connection Strings for LDAP
$ldapconfig['host'] = 'connection';
$ldapconfig['port'] = 389;
$ldapconfig['basedn'] = 'ou=people,ou=unix-domains,dc=domain,dc=com';
// BASEDN
$dn="uid=".$username['user'].",ou=people,".$ldapconfig['basedn'];
// connect to ldap server
$ds = ldap_connect($ldapconfig['host'], $ldapconfig['port'])
or die("Could not connect to LDAP server.");
// binding to ldap server
$login = ldap_bind($ds, $dn, $username['pass']);
////////
$search = ldap_search($ds, "ou=group," . $ldapconfig['basedn'],
"memberuid=$toDelete");
$groupList = ldap_get_entries($ds, $search);
echo $groupList["count"] . " entries returned\n";
$cnGroups = array();
$info["memberuid"] = array();
for( $i=0; $i<$groupList["count"]; $i++ )
{
if( sizeof($groupList[$i]["memberuid"]) != 0 )
{
foreach ( $groupList[$i]["memberuid"] as $val )
{
if ( $val == $toDelete )
{
$cnGroups = "cn=" . $groupList[$i]['cn'][0] . ",$basedn";
$info["memberuid"] = $toDelete;
echo "Deleting " . $toDelete . " from " . $cnGroups . "\n";
$remove = ldap_mod_del($ds, $cnGroups, $info);
echo "$remove\n";
}
}
}
}
?>
----
Server IP: 69.147.83.197
Probable Submitter: 192.88.165.35
----
Manual Page -- http://www.php.net/manual/en/function.ldap-mod-del.php
Edit -- https://master.php.net/note/edit/103349
Del: integrated -- https://master.php.net/note/delete/103349/integrated
Del: useless -- https://master.php.net/note/delete/103349/useless
Del: bad code -- https://master.php.net/note/delete/103349/bad+code
Del: spam -- https://master.php.net/note/delete/103349/spam
Del: non-english -- https://master.php.net/note/delete/103349/non-english
Del: in docs -- https://master.php.net/note/delete/103349/in+docs
Del: other reasons-- https://master.php.net/note/delete/103349
Reject -- https://master.php.net/note/reject/103349
Search -- https://master.php.net/manage/user-notes.php