<!--
  THIS WORK IS SUBJECT TO U.S. AND INTERNATIONAL COPYRIGHT LAWS AND TREATIES.
  USE AND REDISTRIBUTION OF THIS WORK IS SUBJECT TO THE LICENSE AGREEMENT 
  ACCOMPANYING THE SOFTWARE DEVELOPMENT KIT (SDK) THAT CONTAINS THIS WORK.
  PURSUANT TO THE SDK LICENSE AGREEMENT, NOVELL HEREBY GRANTS TO DEVELOPER 
  A ROYALTY-FREE, NON-EXCLUSIVE LICENSE TO INCLUDE NOVELL'S SAMPLE CODE IN 
  ITS PRODUCT. NOVELL GRANTS DEVELOPER WORLDWIDE DISTRIBUTION RIGHTS TO MARKET,
  DISTRIBUTE, OR SELL NOVELL'S SAMPLE CODE AS A COMPONENT OF DEVELOPER'S PRODUCTS.
  NOVELL SHALL HAVE NO OBLIGATIONS TO DEVELOPER OR DEVELOPER'S CUSTOMERS WITH 
  RESPECT TO THIS CODE. 
 
 Name           : LDAPQUERY.PHP
 Description    : This script performs a simple LDAP query
 Author         : SVR
 Date           : 1st May 2002
-->

<html>

<head>
<title>LDAP Query Test</title>
</head>

<body>
<font face="Courier New" size="-1">

<h3>LDAP Query Test</h3>

<?php
 $ds = ldap_connect("www.nldap.com");  // must be a valid LDAP server!
 echo "connect result is ".$ds."<p>";

 if ($ds) { 
     $r=ldap_bind($ds);     // this is an "anonymous" bind, typically
                            // read-only access
     echo "Bind result is ".$r."<p>";

     // Search surname entry
     $sr=ldap_search($ds,"c=US", "sn=S*");  
     echo "Search result is ".$sr."<p>";

     echo "Number of entires returned is ".ldap_count_entries($ds,$sr)."<p>";

     $info = ldap_get_entries($ds, $sr);
     echo "Data for ".$info["count"]." items returned:<p>";

     for ($i=0; $i<$info["count"]; $i++) {
         echo "dn is: ". $info[$i]["dn"] ."<br>";
         echo "first cn entry is: ". $info[$i]["cn"][0] ."<br>";
         echo "first email entry is: ". $info[$i]["mail"][0] ."<p>";
     }

     ldap_close($ds);

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

</font>

</body>

</html>
