ldap_search() problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Dirceu
Forum Newbie
Posts: 2
Joined: Tue Aug 29, 2006 11:57 am

ldap_search() problem

Post 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.
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post by Ambush Commander »

Code please.
Dirceu
Forum Newbie
Posts: 2
Joined: Tue Aug 29, 2006 11:57 am

Post by Dirceu »

feyd | Please use

Code: Select all

,

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

,

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]
Last edited by Dirceu on Tue Aug 29, 2006 9:50 pm, edited 1 time in total.
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post by Ambush Commander »

Err, you're very welcome! :D
Post Reply