Location: PHPKode > projects > Network Asset Management Archive > nama/ldap.php
<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
$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">';
<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>


    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]) ."&nbsp</td>";
        echo '<td><A HREF="mailto:'. $info[$i]["cn"][0] . '&nbsp">' .  $info[$i]["cn"][0] . '</td>';
        echo '<td><A HREF="mailto:'. $info[$i]["mail"][0] . '&nbsp">' .  $info[$i]["mail"][0] . '</td>';
        echo "<td>". $info[$i]["givenname"][0] ."&nbsp</td>";
        echo "<td>". $info[$i]["initials"][0] ."&nbsp</td>";
        echo "<td>". $info[$i]["sn"][0] ."&nbsp</td>";
        echo "<td>". $info[$i]["telephonenumber"][0] ."&nbsp</td>";
        echo "<td>". $lab ."&nbsp</td>";
        echo "</tr>";
echo "</table>";

    echo "Closing connection";

} else {
    echo "<h4>Unable to connect to LDAP server</h4>";
Return current item: Network Asset Management Archive