_id)
{
//认证
$bind_id = ldap_bind($connect_id);
//执行搜索
$search_id = ldap_search($connect_id, $LDAP_ROOT_DN[$SERVER_ID], $ldap_query);
//将结果集合分配给一个数组
$result_array = ldap_get_entries($connect_id, $search_id);
}
else
{
//显示连接错误
echo "Could not connect to LDAP server: $LDAP_SERVER[$SERVER_ID]";
}
//如果搜索成功,将结果排序
if($result_array)
{
for($i=0; $i {
$format_array[$i][0] = strtolower($result_array[$i]["cn"][0]);
$format_array[$i] = $result_array[$i]["dn"];
$format_array[$i] = strtolower($result_array[$i]["givenname"][0]);
$format_array[$i] = strtolower($result_array[$i]["sn"][0]);
$format_array[$i] = strtolower($result_array[$i]["mail"][0]);
}
//排序数组
sort($format_array, "SORT_STRING");
for($i=0; $i {
$cn = $format_array[$i][0];
$dn = $format_array[$i];
$fname = ucwords($format_array[$i]);
$lname = ucwords($format_array[$i]);
$email = $format_array[$i];
if($dn && $fname && $lname && $email)
{
$result_list .= "<A href=''/"ldap://$LDAP_SERVER[$SERVER_ID]/$dn/"''>$fname $lname</A>";
$result_list .= " 〈$email〉
\n";
}
elseif($dn && $cn && $email)
{
$result_list .= "<A href=''/"ldap://$LDAP_SERVER[$SERVER_ID]/$dn/"''>$cn</A>";
$result_list .= " 〈<A href=''/"mailto:$email/"''>$email</A>
\n";
}
}
}
else
{
echo "Result set empty for query: $ldap_query";
}
//关闭连接
ldap_close($connect_id);
//定制表格
echo " <CENTER><FORM action=''\"$PHP_SELF\"'' method=''\"GET\"''>";
echo "Search in:<SELECT name=''\"SERVER_ID\"''>"; //循环以建立SELECT选项 for($i=0; $i echo "<OPTION selected value=''\"$i\"''>".$LDAP_NAME[$i]."</OPTION>"; echo "</SELECT>
";
echo "Search for:<INPUT name=''\"common\"'' type=''\"text\"''>";
echo "<INPUT name=''\"lookup\"'' type=''\"submit\"'' value=''\"go\"''>
";
echo "(You can use * for wildcard searches, ex. * Stanley will find all Stanleys)
";
echo "</FORM></CENTER>";
//显示结果
if($result_list)
{
echo " <CENTER><TABLE border=''\"1\"'' cellPadding=''\"10\"'' cellSpacing=''\"0\"''
BGCOLOR=\"#FFFFEA\" WIDTH=\"450\"> <TBODY><TR><TD>$result_list</TD></TR>
</TBODY></TABLE></CENTER>";
}
else
echo "No Results";
}
?>