note 47432 added to function.ldap-first-reference

From: Date: Tue, 16 Nov 2004 11:56:30 +0000
Subject: note 47432 added to function.ldap-first-reference
Groups: php.notes 
Request: Send a blank email to php-notes+get-80584@lists.php.net to get a copy of this message
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 . "<br>\n"; } } $ref = ldap_next_reference($adConn, $ref); } ---- Manual Page -- http://www.php.net/manual/en/function.ldap-first-reference.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+47432 Delete -- http://master.php.net/manage/user-notes.php?action=delete+47432&report=yes Reason: bad code -- http://master.php.net/manage/user-notes.php?action=delete+47432&report=yes&reason=bad+code Reason: spam -- http://master.php.net/manage/user-notes.php?action=delete+47432&report=yes&reason=spam Reason: useless example -- http://master.php.net/manage/user-notes.php?action=delete+47432&report=yes&reason=useless+example Reason: contains commercial links -- http://master.php.net/manage/user-notes.php?action=delete+47432&report=yes&reason=contains+commercial+links Reason: useless note -- http://master.php.net/manage/user-notes.php?action=delete+47432&report=yes&reason=useless+note Reject -- http://master.php.net/manage/user-notes.php?action=reject+47432&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#80584) next »