note 103903 added to function.ldap-read

From: Date: Tue, 10 May 2011 12:30:10 +0000
Subject: note 103903 added to function.ldap-read
Groups: php.notes 
Request: Send a blank email to php-notes+get-179578@lists.php.net to get a copy of this message
Try it, "dn" is username <?php // basic sequence with LDAP is connect, bind, search, interpret search // result, close connection $server = 'xxx.xxx.xxx.xxx'; $dn = 'xxxxx'; $pw = 'xxxx'; $searchstring="(objectclass=*)"; //$attnames=array("dn","cn","surname","mail","groupmembership"); $ds=ldap_connect($server); // must be a valid LDAP server! if ($ds) { $r=ldap_bind($ds, $dn, $pw); // read-only access if($r) echo "ldap_bind success<br>"; //ldap_search searches sub. //ldap_list searches one level. //ldap_read searches base. $r=ldap_search($ds,"cn=*,DC=*", $searchstring); if($r) echo "ldap_search success<br>"; echo "Number of entires returned is ".ldap_count_entries($ds,$r)."<p>"; $entries = ldap_get_entries($ds, $r); echo "Data for ".$entries["count"]." items returned:<p>"; for ($i=0; $i<$entries["count"]; $i++) { echo "<p>"; // Any multi-valued object will return like the following: // $entries[0]['mail']['count']=2 // $entries[0]['mail'][0]='a@b.com' // $entries[0]['mail'][1]='b@b.com' foreach($attnames as $attname){ if(is_array($entries[$i][$attname])){ for($j=0;$j<$entries[$i][$attname]["count"];$j++){ echo $attname." entry is: ". $entries[$i][$attname][$j] ."<br>"; } }else{ echo $attname." entry is: ".$entries[$i][$attname]."<br>"; } } echo "</p>"; } ldap_close($ds); } else { echo "<h4>Unable to connect to LDAP server</h4>"; } ?> ---- Server IP: 69.147.83.197 Probable Submitter: 220.225.128.226 ---- Manual Page -- http://www.php.net/manual/en/function.ldap-read.php Edit -- https://master.php.net/note/edit/103903 Del: integrated -- https://master.php.net/note/delete/103903/integrated Del: useless -- https://master.php.net/note/delete/103903/useless Del: bad code -- https://master.php.net/note/delete/103903/bad+code Del: spam -- https://master.php.net/note/delete/103903/spam Del: non-english -- https://master.php.net/note/delete/103903/non-english Del: in docs -- https://master.php.net/note/delete/103903/in+docs Del: other reasons-- https://master.php.net/note/delete/103903 Reject -- https://master.php.net/note/reject/103903 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#179578) next »