Create an LDAP Address Book with PHP - Close Connection
(Page 4 of 6 )
Now that we have all of our data contained in $result_list, we can safely disconnect from the LDAP connection.
<?php
//Close Connection
ldap_close($connect_id);
?> Make HTML Form for Search Interface
Finally, we get to the HTML output of the script.
This set of code prints out the form that is used for performing the searches.
<?php
//Make Form
echo "<CENTER><FORM ACTION=\"$PHP_SELF\" METHOD=\"GET\">";
echo "Search in: <SELECT NAME=\"SERVER_ID\">";
//Loop Through and Create SELECT OPTIONs
for($i=0; $i echo "<OPTION VALUE=\"$i\">".$LDAP_NAME[$i]." </OPTION>";
echo "</SELECT><BR>";
echo "Search for: <INPUT TYPE=\"text\" NAME=\"common\">";
echo "<INPUT TYPE=\"submit\" NAME=\"lookup\" VALUE=\"go\"><BR>";
echo "(You can use * for wildcard searches, ex. * Stanley will find all Stanleys) <BR>";
echo "</FORM></CENTER>";
?> The only portions of this code that is interpreted is $PHP_SELF which is a global constant for the name of the script itself and the loop that creates the SELECT box from our $LDAP_NAME variable.
Echo Results Now that all of the work has been done, we print out the result set. If no results were returned, a message is given stating the same.
<?php
//Echo Results
if($result_list)
{
echo "<CENTER><TABLE BORDER=\"1\" CELLSPACING=\"0\" CELLPADDING=\"10\" BGCOLOR=\"#FFFFEA\" WIDTH=\"450\"><TR><TD>$result_list</TD></TR> </TABLE></CENTER>";
}
else
echo "No Results";
?> Next: Source Code >>
More PHP Articles
More By Dannie Stanley