tags:

views:

390

answers:

3

How can i get all the users from the LDAP using PHP.

function getUsers() {

      $process = new process();
    //ldap->s_Host('domain.com');
    //$ldap->s_Domain('domain.com');
     $process->s_Host('domain.com');
     $process->s_Domain('domain.com');   
     $process->s_LdapSecure(false);

      if($process->LdapConn()){
             if($process->LdapBind()){



     }

}
}
+4  A: 

That's a question like "How do I land an airplane?"... :-)

You need to provide a lot more details on what you're going to do, what you've already done and so on...

First of all it depends on what type of LDAP server your talking of (OpenLDAP or Active Directory for example) and what LDAP schema the server uses (Active Directory has a clear standard on this but especially OpenLDAP can store users in an arbitrary schema). If you've figured out these details you can famliarize yourself with ext/ldap, which is the LDAP extension library for PHP, or some higher abstraction such as PEAR's Net_LDAP2. If you have a basic understand on how LDAP communication works and if you encounter problems in executing the whole thing in PHP with ext/ldap you should edit your question to be more specific.

In general a LDAP communication session involves:

  • connecting to the server: ldap_connect()
  • binding to the server (aka authenticating with a user that has the appropriate access right): ldap_bind()
  • carry out operations on the server
  • close the connection: ldap_unbind()

The carry out operations on the server (in your case: retrieve all user accounts) now strongly depends on the server and/or schema you're using.

Stefan Gehrig
I have riposted further, can you help me
/me runs off to launch airplanelanding using stackexchange
seth
A: 

Watch out for limits... AD defaults to 1000 objects returned, so you will have a problem, if there are more objects than that in the AD domain. eDirectory lets you configure the number number, but defaults to unlimited. OpenLDAP, dunno.

You probably want to specify an attribute to retrieve, even if only cn or uid, else the default is all attributes, which would be rank foolishness.

You may wish to scope it to an objectClass (say user, inetorgperson or the like, depending on your backend server).

geoffc
A: 

New to the JDNI API and wish to know if anyone can do this same thing with Java. Just am looking for a working example to see where I can go from there. Some help would be much appreciated :D

Fred Laderoute