11.07.2015 Views

PHP MySQL - Stilson.net

PHP MySQL - Stilson.net

PHP MySQL - Stilson.net

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

CHAPTER 17 • <strong>PHP</strong> AND LDAPwww.it-ebooks.inforesource ldap_read(resource link_id, string base_dn, string filter[, array attributes [, int attributes_only [, int size_limit[, int time_limit [int deref]]]]])For example, to retrieve the first and last name of a user identified only by his user ID, you mightexecute the following:$host = "ldap.wjgilmore.com";// Who are we looking for?$dn = "uid=wjgilmore,ou=People,dc=WJGilmore,dc=com";// Connect to the LDAP server$connection = ldap_connect($host)or die("Can't establish LDAP connection");ldap_set_option($connection, LDAP_OPT_PROTOCOL_VERSION, 3);// Bind to the LDAP serverldap_bind($connection) or die("Can't bind to the server.");// Retrieve the desired information$results = ldap_read($connection, $dn, '(objectclass=person)',array("givenName", "sn"));// Retrieve an array of returned records$entry = ldap_get_entries($connection, $results);// Output the first and last namesprintf("First name: %s ", $entry[0]["givenname"][0]);printf("Last name: %s ", $entry[0]["sn"][0]);// Close the connectionldap_unbind($connection);This returns the following:First Name: WilliamLast Name: GilmoreCounting Retrieved EntriesIt’s often useful to know how many entries are retrieved from a search. <strong>PHP</strong> offers one explicit functionfor accomplishing this, ldap_count_entries(). Its prototype follows:358

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!