如何通过PHP进行Active Directory查找?无需重新编译PHP。 PHP的版本是5.3通过PHP的Active Directory查找
我想从他们的用户名找到人显示名称。 Web服务器是IIS 6,PHP使用FastCGI提供服务。
我得到的用户名:
$cred = explode('\\',$_SERVER['REMOTE_USER']);
if (count($cred) == 1) array_unshift($cred, "(no domain info - perhaps SSPIOmitDomain is On)");
list($domain, $user) = $cred;
return $user;
所以,我怎样才能再找到名字?例如DoeJ =李四
编辑:
试图查找用户,但不知道如何找到 “基本DN”。不能直接访问Active Directory服务器或具有管理员权限,因此不能匿名连接。
<?php
//using ldap bind anonymously
// connect to ldap server
$ldapconn = ldap_connect("example.co.uk")
or die("Could not connect to LDAP server.");
if ($ldapconn) {
// binding anonymously
$ldapbind = ldap_bind($ldapconn);
if ($ldapbind) {
echo "LDAP bind anonymous successful...";
ldap_set_option($ldapconn, LDAP_OPT_PROTOCOL_VERSION,3);
ldap_set_option($ldapconn, LDAP_OPT_REFERRALS,0);
$dn = "CN=Users"; // also tried DC=example,DC=co,DC=uk
$filter="(SAMAccountName=username)";
$justthese = array("ou", "sn", "givenname", "mail");
$sr=ldap_search($ldapconn, $dn, $filter, $justthese);
$info = ldap_get_entries($ds, $sr);
echo $info["count"]." entries returned\n";
} else {
echo "LDAP bind anonymous failed...";
}
}
?>
失败的ldap_search:警告:ldap_search()[function.ldap搜索]:搜索:操作错误
如果我使用'ldapbind = ldap_bind($ ldapconn);'它返回true,所以假定允许匿名绑定。还尝试了'$ filter =“(sAMAccountName ='username')”;'所以不知道它是否在过滤级别失败,DN或'$ justthese' – SamWM
不要在过滤字符串中引用用户名('$ filter =“(sAMAccountName = username)”;'** NOT **' $ Filter =“(sAMAccountName ='username')”;') 也许我没有解释这100%正确:Active Directory不允许匿名用户读取除'RootDSE'之外的其他条目,这是绝对根目录LDAP树。所以'ldap_bind()'确实可以返回'true',但这并不意味着你被允许访问LDAP树。 考虑到错误消息,我假设你的* base DN *是第一个要解决的问题。 –