Novell is now a part of Micro Focus

Sample Code - Search eDirectory in PHP using LDAP

Novell Cool Solutions: Feature

Digg This - Slashdot This

Posted: 2 Aug 2005

Note: You will need to supply the IP address for the $server statement. You can also find this sample code at:

Sample Code

// basic sequence with LDAP is connect, bind, search, interpret search
// result, close connection

$server = '137.x.x.x';
$dn = 'cn=admin,o=novell';
$pw = 'novell';

$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,"o=novell", $searchstring, $attnames);  
	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]=''
		// $entries[0]['mail'][1]=''
		foreach($attnames as $attname){
					echo $attname." entry is: ". $entries[$i][$attname][$j] ."<br>";
				echo $attname." entry is: ".$entries[$i][$attname]."<br>";
		echo "</p>";

} else {
    echo "<h4>Unable to connect to LDAP server</h4>";

Novell Cool Solutions (corporate web communities) are produced by WebWise Solutions.

© Copyright Micro Focus or one of its affiliates