1
我正在使用LDAP來驗證用戶的登錄表單上工作。但是我不知道如何將用戶名作爲POST變量和DN憑證一起傳遞。這是工作讓我從一個登錄表單發送密碼:使用POST變量進行UID的LDAP綁定?
<?php
// using ldap bind
$ldaprdn = 'uid=my.name,cn=XXX,dc=XXX,dc=XXX,dc=XXX'; // ldap rdn or dn
$ldappass = $_POST['userPassword']; // user password
// connect to ldap server
$ldapconn = ldap_connect("server.domain.com")
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, $ldaprdn, $ldappass);
// verify binding
if ($ldapbind) {
echo "LDAP bind successful...\n";
} else {
echo "LDAP bind failed...\n";
}
}
?>
然而,這並不試圖追加包含的POST變量的CN和DN值範圍內的值時。
<?php
// using ldap bind
$ldaprdn = "uid = . $_POST['userLogin'] . 'cn=XXX,dc=XXX,dc=XXX,dc=XXX'"; // ldap rdn or dn
$ldappass = $_POST['userPassword']; // user password
// connect to ldap server
$ldapconn = ldap_connect("server.domain.com")
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, $ldaprdn, $ldappass);
// verify binding
if ($ldapbind) {
echo "LDAP bind successful...\n";
} else {
echo "LDAP bind failed...\n";
}
}
?>
這樣可以這樣做嗎?我相信,我只可以使用的ldap_bind函數傳遞三個變量,
非常感謝
服務器日誌記錄在客戶使用'userLogin'的情況? – 2013-05-13 11:39:40
嗨,我收到一個錯誤:slapd [41]:conn = 22795 op = 0 do_bind:無效dn(cn = XXX,dc = XXX,dc = XXX,dc = XXX,uid = $ _ POST [「userLogin」]' ) 謝謝 – m1243 2013-05-13 13:02:10