我正在尝试使用PHP创建登录页面。
目标:
1.用户可以使用登录Windows时使用的相同用户名/密码登录
2.用户将被重定向到一个页面,具体取决于他所属的组
所以第一个目标就解决了。现在的问题是第二个目标。
运行脚本时出错:
Warning: ldap_search(): Search: Bad search filter
脚本:
$ldap['user'] = "domain\user123";
$ldap['pass'] = "password123";
$ldap['host'] = 'site.domain.com';
$ldap['port'] = 389;
$ldap['dn'] = "DC=site, DC=domain, DC=com";
$ldap_user_group = "User";
$ldap_manager_group = "Admin";
$ldap['conn'] = ldap_connect( $ldap['host'], $ldap['port'] )
or die("Could not connect to {$ldap['host']}" );
$ldap['bind'] = ldap_bind($ldap['conn'], $ldap['user'], $ldap['pass']);
if( !$ldap['bind'] )
{
echo "Login Failed";
}
else if( $ldap['bind'] )
{
$filter = "(sAMAccountName=" . $ldap['user'] . ")";
$attr = array("memberof");
$result = ldap_search($ldap['conn'],$ldap['dn'], $filter, $attr)
or exit("Unable to search LDAP server");
$entries = ldap_get_entries($ldap['conn'], $result);
ldap_unbind($ldap);
foreach($entries[0]['memberof'] as $grps)
{
if (strpos($grps, $ldap_manager_group))
{
//redirect to Admin page
}
if (strpos($grps, $ldap_user_group))
{
//redirect to User page
}
}
我真的迷失了,因为我不知道造成这个错误的原因。
先谢谢你的帮助!!!
答案 0 :(得分:1)
当您将斜杠传入过滤器时,会出现错误的搜索过滤器。您在此处使用$ldap['user'] = "domain\user123";
$filter = "(sAMAccountName=" . $ldap['user'] . ")";
根据您的AD设置,您可能希望使用类似$filter = "(sAMAccountName=user123)";