I used ldap in this way:
<HTML>
<BODY>
<FORM METHOD="POST" ACTION="ldap.php">
To search for someone from an LDAP server, type in the name of the server:<BR>
<INPUT TYPE="text" NAME="server">
type in the search base:
<INPUT TYPE="text" NAME="search_base">
type in part of their surname:
<INPUT TYPE="text" NAME="part_name">
<INPUT TYPE="submit" VALUE="Run query">
</FORM>
</BODY>
</HTML>
And here is some PHP code to access the LDAP server. It uses six functions:
* ldap_connect and ldap_bind connects and binds to the LDAP server running on a given computer;
* ldap_search requests the LDAP server to search for entries containing a particular string;
* ldap_get_entries returns an array containing the entries that were found.
* ldap_close closes the connection to the LDAP server.
Here is the code of the ldap.php script:
<HTML>
<BODY>
<?php
$server = $_POST["server"];
$search_base = $_POST["search_base"];
$part_name = $_POST["part_name"];
$c_result = ldap_connect("$server");
$b_result = ldap_bind($c_result);
$s_result = ldap_search($c_result, "$search_base", "cn=*$part_name*");
$info = ldap_get_entries($c_result, $s_result);
$numrows = $info["count"];
if ( $numrows == 0 ) {
echo "<P>There is no entry with a name of $part_name</P>";
echo "</BODY></HTML>";
ldap_close($c_result);
exit;
}
?>
<TABLE BORDER="1">
<?php
for ($rownum = 0; $rownum<$numrows; $rownum++) {
?>
<TR>
<TD>
<?php echo $info[$rownum]["cn"][0]; ?>
</TD>
<TD>
<?php echo $info[$rownum]["ou"][0]; ?>
</TD>
<TD>
<?php echo $info[$rownum]["telephonenumber"][0]; ?>
</TD>
<TD>
<?php
echo "<A HREF=mailto:";
echo $info[$rownum]["mail"][0];
echo ">";
echo $info[$rownum]["mail"][0];
echo "</A><BR>";
?>
</TD>
</TR>
<?php
}
?>
</TABLE>
<?php
ldap_close($c_result);
?>
</BODY>
</HTML>
Hope this helps you a bit.
--=][tReShR][=--