Page 1 of 1
ldap_search() problem
Posted: Tue Aug 29, 2006 12:00 pm
by Dirceu
Problem with the ldap_search() of the php
I've been searching all the values of the uidNumber attribute in a base with the objectClass=* filter and only 23 entries returned to my script as opposed to the 522 entries in the phpLDAPadmin which is correct! .
I've already tried and searched in the phpLDAPadmin code but couldn't find the difference.
Thanks for any help.
Posted: Tue Aug 29, 2006 8:42 pm
by Ambush Commander
Code please.
Posted: Tue Aug 29, 2006 9:22 pm
by Dirceu
feyd | Please use Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
thanks for your help!
Increadible as it seems the moment I started copying in the code I realised where I was doing wrong! So I'm sending it to you for appreciation.
Code: Select all
$ds = ldap_connect("localhost");
$bind = ldap_bind($ds, "cn=manager,dc=example,dc=br", "pass") or die(ldap_error($ds));
function uidnumber($ds,$base_dn)
{
$justthese = array("uidNumber");
$filter = "(objectClass=*)";
$sr = ldap_search($ds,$base_dn,$filter, $justthese, 0, 0, 0, LDAP_DEREF_NEVER) or die(ldap_error($ds));
$sinfo = ldap_get_entries($ds, $sr) or die(ldap_error($ds));
$attrib = "uidnumber";
switch ($sinfo["count"])
{
case 0 :
$sorted = $GLOBALS['first_uid'] - 1;
break;
case 1 :
$sorted = $sinfo[0][$attrib][0];
break;
default :
for ($i = 0; $i < $sinfo["count"]; $i++)
{
$a = (int)$sinfo[$i][$attrib][0];
$arr[$i] = $a;
}
sort($arr,SORT_NUMERIC);
reset($arr);
$sorted = array_pop($arr);
break;
}
$uidnumber = $sorted + 1;
return $uidnumber;
}
echo uidnumber($ds,"ou=users,dc=example,dc=br");
ldap_close($ds);
Thank you very much!!!
feyd | Please use Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Posted: Tue Aug 29, 2006 9:23 pm
by Ambush Commander
Err, you're very welcome!
