Auth_Ldap: LDAP Authentication Library for CodeIgniter


This was first presented in my post LDAP Authentication with CodeIgniter.  This is just a simple library that wraps up the necessary LDAP calls to authenticate a user against LDAP and then set a session cookie that identifies the user as logged in.

Usage is relatively simple: unpack the archive and copy the files into the appropriate CodeIgniter libraries for your application.  This usually just means mirroring the directory structure in the zip file over to your CodeIgniter install.  The directory structure should look something like this:

The files controllers/auth.php, views/auth/login_form.php, and views/auth/logout_view.php are not necessary for the functionality of the library and are provided as an example of how to use AuthLDAP within your application.


AuthLDAP (3442)
 Posted by at 14:00:40 pm

  13 Responses to “Auth_Ldap: LDAP Authentication Library for CodeIgniter”

  1. Hi,

    Am getting the following error when configuring for Active Directory:

    Error looking up DN for coolvixs: Success

    My configs as follows:

    $config['ldap_uri'] = array(‘ldap://’);
    $config['use_tls'] = false; // Using SSL above, don’t use TLS with it
    $config['search_base'] = ‘DC=example,DC=com’;
    $config['user_search_base'] = ”;
    $config['group_search_base'] = ”;
    $config['user_object_class'] = ‘user’;
    $config['group_object_class'] = ‘group’;
    $config['user_search_filter'] = ”;
    $config['group_search_filter'] = ”;
    $config['login_attribute'] = ‘sAMAccountName’;
    $config['schema_type'] = ‘ad’; // Could also use rfc2307bis
    $config['proxy_user'] = ‘CN=Admin,CN=Users,DC=staff,DC=example,DC=com
    $config['proxy_pass'] = ‘xxxxxx’;
    $config['roles'] = array(1 => ‘User’,
    3 => ‘Power User’,
    5 => ‘Administrator’);
    $config['auditlog'] = ‘application/logs/audit.log’;

    Would be grateful if you could advise where am going wrong…

    Thanks in advance

  2. Hello.

    I would like to ask your help.

    can you write down step by step to install this in CI.


  3. Thanks a lot for this script ! I’ll test it ! :)

  4. Thanks for the great plugin. I have updated to the newer version and now I’m getting this error:

    Message: ldap_connect() [function.ldap-connect]: Could not create session handle: Bad parameter to an ldap routine

  5. im succes to login, but i want to know my uid_number and gid_number, can u help me

  6. libraries/AuthLDAP.php line 193 – uses ldapconn() as a function when it’s a variable; need to drop the ()

    controlllers/auth.php refers to ‘authldap.php’ when it should be ‘AuthLDAP.php’; I’m guessing you are using a case insensitive filesystem/OS.

  7. Thanks for this useful script. Saved me some time.

    For my uses, I had to disable all mentions of roles in order for everything to work. We don’t set anything like this where I work and I don’t have control over it. It took me a while to figure that out, though, because the error message I received said “Group search successful but no memberships were found.”

    After commenting out all things related to roles and removing any vars that were related to roles, everything worked great.

    The next helpful thing I did was autoload the session library. This is key if you want to be able to access the session vars that this library sets. Then in my “view page” controller, I check to see if ‘logged_in’ is set before showing the user anything.

    [code]$this->session->userdata('logged_in') ? null : redirect('auth');[/code]

    I hope this is useful to anyone else who runs into it.

  8. Thanks.

    If I want to know a list of groups that the logged members is, how can I do that?

    I need to authenticate a user who is in a group (intranet or intranetAdmins). How can I proceed?

    Again, thanks!

  9. Hello,

    I just got a question :

    In my company, we use different mail address, but a same Domain

    ex: DOMAIN\user ¬

    The thing I want to know is that : Do I need to modify the library for the authentication (and set in the config file le prefeix needed) ? I talk about this here, because it could be useful to add in this library !

  10. […] I am using the ldap library for Codeigniter written by Greg Wojtak from auth_ldap_library. […]

 Leave a Reply



You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">