我正在使用 LDAP 登录系统。目前,我可以使用 AD 帐户登录系统。问题是,我的系统有两种类型的用户。(管理员可以读写,而另一个是只能读取的普通用户)。如何在这两个用户之间进行过滤,以便管理员登录时,他们将被带到他们的 HomeScreen.php,而普通用户将被带到 HomeScreen2.php。
这是我到目前为止所做的 LDAP 编码(不包括登录表单):
set_time_limit(30);
error_reporting(E_ALL);
ini_set('error_reporting', E_ALL);
ini_set('display_errors',1);
///config
$ldapserver = "server.name";
$ldapport = 389;
$base_dn = "DC=xyz,DC=local";
$ldapuser = isset($_POST['username']) ? $_POST['username'] : '';
$ldappass = isset($_POST['password']) ? $_POST['password'] : '';
$ldaptree = "CN=ITInfra,OU=Groups,OU=MYABC,DC=xyz,DC=local";
$domain = '@abcd.local';
// connect
$ldapconn = ldap_connect($ldapserver,$ldapport) or die ("Could not connect to LDAP
server.");
// Set some ldap options for talking to
ldap_set_option($ldapconn, LDAP_OPT_PROTOCOL_VERSION, 3);
ldap_set_option($ldapconn, LDAP_OPT_REFERRALS, 0);
if ($ldapconn) {
// binding to ldap server
//$ldapbind = @ldap_bind($ldapconn, $ldapuser.$domain, $ldappass) or die ("<b>
<center><font color='red'>WARNING! : ".ldap_error($ldapconn));
$ldapbind = @ldap_bind($ldapconn, $ldapuser.$domain, $ldappass) or
die("<b><center><font color='red'>WARNING!<br> The username or password you entered is
incorrect");
// verify binding
if ($ldapbind) {
$result = @ldap_search($ldapconn,$ldaptree, "(ou=*)") or die ("<b>
<center><font color='red'>Please enter username & password");
echo "<b><center><font color='blue'> Congratulations! $ldapuser is
authenticated.\n";
header('Location: HomeScreen.php');
} else {
echo "LDAP bind failed...\n";
}
}
// all done? clean up
ldap_close($ldapconn);