<?php
$LDAP_NAME[0] = "Netscape Net Center";
$LDAP_SERVER[0] = "memberdir.netscape.com";
$LDAP_ROOT_DN[0] = "ou=member_directory,o=netcenter.com";
$LDAP_NAME[1] = "Bigfoot";
$LDAP_SERVER[1] = "ldap.bigfoot.com";
$LDAP_ROOT_DN[1] = "";
//如果没有选择服务器的话将它设置为0
if(!$SERVER_ID)
$SERVER_ID=0;
//建立查询
$ldap_query = "cn=$common";
//连接到LDAP
$connect_id = ldap_connect($LDAP_SERVER[$SERVER_ID]);
if($connect_id)
{
//认证
$bind_id = ldap_bind($connect_id);
//执行搜索
//将结果集合分配给一个数组
$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][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($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 .= "<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>";