I've been looking for something to let users look up other users' email addresses easily, as the Outlook Express address book won't let you just display them all. I found a PHP script that works great. You can find it at
http://www.chrouch.com/ldapsearch.php and the source is below.
----------------------------------
$LDAP_NAME[0] = " SME Server ";
$LDAP_SERVER[0] = "localhost";
$LDAP_ROOT_DN[0] = "";
//If no server chosen set it to 0
if(!$SERVER_ID)
$SERVER_ID=0;
//Create Query
$ldap_query = "cn=*$common*";
//Connect to LDAP
$connect_id = ldap_connect($LDAP_SERVER[$SERVER_ID]);
if($connect_id)
{
//Authenticate
$bind_id = ldap_bind($connect_id);
//Perform Search
$search_id = ldap_search($connect_id, $LDAP_ROOT_DN[$SERVER_ID], $ldap_query);
//Assign Result Set to an Array
$result_array = ldap_get_entries($connect_id, $search_id);
}
else
{
//Echo Connection Error
echo "Could not connect to LDAP server: $LDAP_SERVER[$SERVER_ID]";
}
//Sort results if search was successful
if($result_array)
{
for($i=0; $i
{
$format_array[$i][0] = strtolower($result_array[$i]["cn"][0]);
$format_array[$i][1] = $result_array[$i]["dn"];
$format_array[$i][2] = strtolower($result_array[$i]["givenname"][0]);
$format_array[$i][3] = strtolower($result_array[$i]["sn"][0]);
$format_array[$i][4] = strtolower($result_array[$i]["mail"][0]);
}
//Sort array
sort($format_array, "SORT_STRING");
for($i=0; $i
{
$cn = $format_array[$i][0];
$dn = $format_array[$i][1];
$fname = ucwords($format_array[$i][2]);
$lname = ucwords($format_array[$i][3]);
$email = $format_array[$i][4];
if($dn && $fname && $lname && $email)
{
$result_list .= "
$fname $lname";
$result_list .= " <
$email>
\n";
}
elseif($dn && $cn && $email)
{
$result_list .= "
$cn";
$result_list .= " <
$email>
\n";
}
}
}
else
{
echo "Result set empty for query: $ldap_query";
}
//Close Connection
ldap_close($connect_id);
//Make Form
echo "

";
echo "
";
//Echo Results
if($result_list)
{
echo "
BGCOLOR=\"#FFFFEA\" WIDTH=\"450\">$result_list |
";
}
else
echo "
No matches found. Please try again.";
?>
----------------------------------
It's fairly simple, and the asterisk wildcards around $common near the beginning will display all users on the system by default, and cause searches to look for anything that contains the typed string. You can remove the asterisk(s) to do "begins with", "ends with", or "exactly" searches as well.
I hadn't been able to find something simple to do what I wanted before this, so I hope it helps someone else out too.