<body text="#000000" bgcolor="#FFFFCC" link="#0000EE" vlink="#551A8B" alink="#FF0000">
<?
echo "<h3>LDAP query test</h3>";
echo "Connecting ...";
$ds=ldap_connect($ldaphost); // must be a valid LDAP server!
echo "connect result is ".$ds."<p>";
if ($ds) {
echo "Binding ...";
$r=ldap_bind($ds); // this is an "anonymous" bind, typically
// read-only access
echo "Bind result is ".$r."<p>";
// Search surname entry
$filter='objectclass=organizationalPerson';
$justthese = array( "ou", "sn", "uid", "givenname", "mail", "telephonenumber", "company", "cn", "initials" );
$sr=ldap_search($ds,$ldapou, $filter, $justthese);
echo "Search result is ".$sr."<p>";
echo "Number of entires returned is ".ldap_count_entries($ds,$sr)."<p>";
echo "Getting entries ...<p>";
$info = ldap_get_entries($ds, $sr);
echo "Data for ".$info["count"]." items returned:<p>";
echo '<table border="3">';
?>
<tr ALIGN=CENTER BGCOLOR="#999999">
<td><b><font face="Times New Roman,Times">UID</font></b></td>
<td><b><font face="Times New Roman,Times">Display Name</font></b></td>
<td><b><font face="Times New Roman,Times">Email</font></b></td>
<td><b><font face="Times New Roman,Times">First Name</font></b></td>
<td><b><font face="Times New Roman,Times">Initial</font></b></td>
<td><b><font face="Times New Roman,Times">Last Name</font></b></td>
<td><b><font face="Times New Roman,Times">Phone</font></b></td>
<td><b><font face="Times New Roman,Times">Lab</font></b></td>
</tr>
<?
for ($i=0; $i<$info["count"]; $i++) {
echo "<tr><td>". $info[$i]["dn"] ."</td>";
if (($info[$i]["company"][0] != '') && (stristr($info[$i]["uid"][0],"u4"))){
$labpos = strpos($info[$i]["company"][0],"-")+1;
$lab = substr($info[$i]["company"][0],$labpos, strlen($info[$i]["company"][0])-$labpos);
echo "<tr><td>". strtoupper($info[$i]["uid"][0]) ." </td>";
echo '<td><A HREF="mailto:'. $info[$i]["cn"][0] . ' ">' . $info[$i]["cn"][0] . '</td>';
echo '<td><A HREF="mailto:'. $info[$i]["mail"][0] . ' ">' . $info[$i]["mail"][0] . '</td>';
echo "<td>". $info[$i]["givenname"][0] ." </td>";
echo "<td>". $info[$i]["initials"][0] ." </td>";
echo "<td>". $info[$i]["sn"][0] ." </td>";
echo "<td>". $info[$i]["telephonenumber"][0] ." </td>";
echo "<td>". $lab ." </td>";
echo "</tr>";
}
}
echo "</table>";
echo "Closing connection";
ldap_close($ds);
} else {
echo "<h4>Unable to connect to LDAP server</h4>";
}
?>