【发布时间】:2009-11-12 09:44:58
【问题描述】:
如何通过 PHP 进行 Active Directory 查找?无需重新编译 PHP。 PHP版本是5.3
我想从他们的用户名中找到一个人的显示名。 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 = John Doe
编辑:
尝试查找用户,但不确定如何找到“基本 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-search]:搜索:操作错误
【问题讨论】:
标签: php active-directory