Welcome to PCCS-Linux.COM Hello, and welcome to the PCCS-Linux Home Page.
Your last visit was !!!
Your Browser is running on Other
 
Using LDAP Functions
I had a request to create an Intranet PhoneBook searchable via a browser...
Having Exchange 5.5 with the LDAP services running, I found some example code
on how to use the LDAP functions at php.net/ldap and started hacking...
 took about 20min...

 
I didn't include the Search Form....

function phoneBook($person)
{
    if(!$this-> person) {
      print "You must search for something!!...";
      print "< br> < A HREF=phonebook.php> Back to Form< /A> ";
      die();
    } else {
    //  Setup connection to server
    // I'm using this function to connect to Exchange 5.5 
    $ds=ldap_connect("");  // must be a valid LDAP server!
    $dn = "o=PCCS-Linux, c=US";

    // We want to search for a person
    // this can be any portion of the name first or last
    $filter="(|(sn=$person*)(givenname=$person*))";
    $justthese = array( "ou", "sn", "givenname", "mail","telephonenumber");

    // Execute the search
    $sr=ldap_search($ds, $dn, $filter, $justthese);

    // Put the results into an array called info
    $info = ldap_get_entries($ds, $sr);

    // Format the results that are returned
    // $info[$1]["valuetoreturn"][0]
    print "< center> ";
    print "< H2> < font color=navy> ".$info["count"]."< /font>  entries
returned< /H2> ";
    print "< table border=0 cellpadding=2 cellspacing=1> ";
    print "< tr> < th>  < /th> < th align=left> Name< /th> <
th align=left> E-Mail< /th> < th align=left> Phone< /th> < /tr> ";
      for($i=0; $i <  count($info); $i++) {

        if($info[$i]["givenname"][0] == "") {
        //
        } else {
            print "< tr bgcolor=#FFFFFF> < td> ";
            print "< a HREF=mailto:".$info[$i]["mail"][0]."> < img
src=".SITE_IMAGES."/sendemail.gif border=0> < /a> < /td> < td> ";
            print $info[$i]["givenname"][0]." ".$info[$i]["sn"][0];
            print "< /td> < td> ";
            print $info[$i]["mail"][0];
            print "< /td> < td> ";
            print $info[$i]["telephonenumber"][0];
            print "< /td> < /tr> ";
        }
      }
    }
   print "< /table> ";
   print "< P> ";

   print "< /center> ";


} // End phoneBook



>> Comments/FeedBack


Page hits 39 last request on :12:21



This web site is prepared and maintained by Chauncey Thorn.
The information contained in this site was valid at the time of posting.
Chauncey Thorn, assumes no liability for damages incurred directly or indirectly as a result of errors, omissions or discrepancies.

Remember most of the content here are my notes...

All logos and trademarks in this site are property of their respective owner. All the rest © by PCCS-Linux.COM

PCCS-Linux.COM ::ource Advocate Articles catalogue
2000 2002