Delicious Bookmark this on Delicious Share on Facebook SlashdotSlashdot It! Digg! Digg



PHP : Function Reference : LDAP Functions : ldap_first_reference

ldap_first_reference

Return first reference (PHP 4 >= 4.0.5, PHP 5)
resource ldap_first_reference ( resource link, resource result )


Code Examples / Notes » ldap_first_reference

sami

Hopefully the code below help you to loop through references with LDAP3 servers. It took me a significant amount of time to figure out how this thing works and now I have successfully used this with Active Directory to loop through severial subdomains.
Special thanks to Stig Venaas who helped me to get started. (the original problem was that ldap_parse_reference function was missing in Windows builds. At least it will now work with Windows PHP versions 5.1.0-DEV and higher after I made a bug report)
function crawlRefs($user, $passw, $host, $dn, $port, $filter) {
 //Create the basic connection for fetching referrals
 $adConn = ldap_connect($host, $port) or die("System couldn't connect!");
 ldap_set_option($adConn, LDAP_OPT_PROTOCOL_VERSION, 3) or die ("System couldn't make first protocol option setting!");
 ldap_set_option($adConn, LDAP_OPT_REFERRALS, 0) or die ("System couldn't make second protocol option setting!");
 $bd = ldap_bind($adConn, $user, $passw) or die ("System couldn't bind the connection!");
 $search = ldap_search($adConn, $dn, $filter);
 //Find referrals
 $ref = ldap_first_reference($adConn, $search);
 while ($ref) {
   if (ldap_parse_reference($adConn, $ref, $referrals)) {
     while ($referral = array_shift($referrals)) {
       echo $referral . "
\n";
     }
   }
 $ref = ldap_next_reference($adConn, $ref);
}


Change Language


Follow Navioo On Twitter
ldap_8859_to_t61
ldap_add
ldap_bind
ldap_close
ldap_compare
ldap_connect
ldap_count_entries
ldap_delete
ldap_dn2ufn
ldap_err2str
ldap_errno
ldap_error
ldap_explode_dn
ldap_first_attribute
ldap_first_entry
ldap_first_reference
ldap_free_result
ldap_get_attributes
ldap_get_dn
ldap_get_entries
ldap_get_option
ldap_get_values_len
ldap_get_values
ldap_list
ldap_mod_add
ldap_mod_del
ldap_mod_replace
ldap_modify
ldap_next_attribute
ldap_next_entry
ldap_next_reference
ldap_parse_reference
ldap_parse_result
ldap_read
ldap_rename
ldap_sasl_bind
ldap_search
ldap_set_option
ldap_set_rebind_proc
ldap_sort
ldap_start_tls
ldap_t61_to_8859
ldap_unbind
eXTReMe Tracker