11.07.2015 Views

PHP MySQL - Stilson.net

PHP MySQL - Stilson.net

PHP MySQL - Stilson.net

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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

www.it-ebooks.infoCHAPTER 17 • <strong>PHP</strong> AND LDAPConsider an example:$host = "ldap.wjgilmore.com";$port = "389";$dn = "dc=WJGilmore,dc=com";$connection = ldap_connect($host)or die("Can't establish LDAP connection");ldap_set_option($connection, LDAP_OPT_PROTOCOL_VERSION, 3);ldap_bind($connection)or die("Can't bind to the server.");// Retrieve all records of individuals having first name// beginning with letter K$results = ldap_search($connection, $dn, "givenName=K*");// Dump records into array$entries = ldap_get_entries($connection, $results);// Determine how many records were returned$count = $entries["count"];// Cycle through array and output name and e-mail addressfor($x=0; $x < $count; $x++) {printf("%s ", $entries[$x]["cn"][0]);printf("(%s) ", $entries[$x]["mail"][0]);}Executing this script produces output similar to this:Kyle Billingsley (billingsley@example.com)Kurt Kramer (kramer@example.edu)Kate Beckingham (beckingham.2@example.edu)Retrieving a Specific EntryYou should use the ldap_read() function when you’re searching for a specific entry and can identify thatentry by a particular DN. Its prototype follows:357

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

Saved successfully!

Ooh no, something went wrong!