0
我可以綁定到AD服務器,但我無法理解如何驗證特定組中的成員身份。我想要做的是檢查用戶是否屬於「DOMAIN \ IT」組,如果有,請指定一個會話變量,以便以後使用。以下是我迄今爲止:使用php和LDAP驗證AD組成員身份
if (isset($_POST["submit"])){
$ldaprdn = "DOMAIN\\" . $_POST["username"]; // ldap rdn or dn
$ldappass = $_POST["password"]; // associated password
} else {
$ldaprdn = "noUserName"; // ldap rdn or dn
$ldappass = "noPassWord"; // associated password
}
//check login form post submission and blank values
if (isset($_POST["submit"])){
if ($_SESSION["blanklogin"] !== "1"){
// connect to ldap server
$ldapconn = ldap_connect("DC01.ROOT.DOMAIN.ORG")
or die("Could not connect to LDAP server.");
if ($ldapconn) {
// binding to ldap server
$ldapbind = ldap_bind($ldapconn, $ldaprdn, $ldappass);
// verify binding
if ($ldapbind) {
$_SESSION["login"] = "1";
TODO: CHECK GROUP MEMBERSHIP - IF IN GROUP DOMAIN\IT then set session variable.
session_regenerate_id(true);
echo "LDAP Bind For "; echo $ldaprdn; echo " successful...";
echo "Login Successful";
header("Location: index.php");
} else {
echo "LDAP bind for "; echo $ldaprdn; echo " Failed...<br />";
$_SESSION["login"] = "0";
}
$_SESSION["blanklogin"] = "0";
ldap_unbind($ldapconn);
}
} else {
echo "Username & Password Required<br />";
}
}
很好,非常感謝你@Ashigore! –