Singapore CMS Web Design

Gary Consulting Group - Singapore CMS Web Design

Timely Support and Clarity in your journey to harness the power of the internet
Email:
sales@name1price.com
Call:
+1 415 300-0019

Search for Lesson

Using PHP with the Active Directory - the first to configuring your Joomla to use LDAP

This tutorial teaches you how to setup a php script to integrate with an Active Directory.

In this. particular active directory, I setup my domain as Testing.local as you can see in the top left hand corner of the above image. I have created two user accounts one called god and the other called gary ZW. Teh. The login id for  gary ZW. Teh is garyjob

account god is an administrators account

account garyjob is a domain user account

 Below is the chunk of code that does the connection and retrieval of the information from the active directory

 <?php
        /*
               cn=users -> means I am only interested in user account types from the active directory
               DC=Testing -> refers to the first part of my domain name within Testing.local
               DC=local -> refers to the second part of my domain name within Testing.local 

        */
        $dn = "cn=users, DC=testing,DC=local";


        /*
               Those indicated within the array below are the fields from the active directory I am interested in retrieving
        */
        $attributes = array("ou", "sn", "givenname", "mail", "name");

        /*
              This inactive line means I am only interested in retrieving user with name= god

        */
        //$filter = "name=god";

        /*
              This line means want to retrieval all users within the active directory

        */
        $filter = "(cn=*)";

         /*
              This line attempts to establish a connection to the server which the Active Directory is sitting onin this case it is at testing

        */       
        $ad = ldap_connect("ldap://testing")  or die("Couldn't connect to AD!");

 

         /*
              This line tells php to use the protocol for Active Directory as there are many other types of directories and they use different protocols

        */     
        ldap_set_option($ad, LDAP_OPT_PROTOCOL_VERSION, 3);

 

         /*
              Notice that if the account you are attempting to login to the active directory with is just a domain user, you will need to enter the username and domain name as in this format username@domain

        */    

        $bd = ldap_bind($ad,"garyjob@testing.local","password")  or die("Couldn't bind to AD!");

 

         /*
              Notice that if the account you are attempting to login to the active directory with is just a administrator user, you will can just enter the username as in this format username

        */   

        $bd = ldap_bind($ad,"god","password")  or die("Couldn't bind to AD!");
        

         /*
              Now we do the search and retrieve

        */   

         $result = ldap_search($ad, $dn, $filter, $attributes);


         /*
              You will now get the results in the form of an array.

        */  
       $entries = ldap_get_entries($ad, $result);
       print_r($entries );



?>

 
Tuesday, 27th Jun 2017
Content Management System powered by Gary from Name1Price.com