[英]PHP LDAP Login Issue
I am having a little trouble with my PHP LDAP login. 我的PHP LDAP登录有点麻烦。 My first bind is successful, but my second bind is not even if the credentials are correct. 我的第一个绑定成功,但是即使凭据正确,我的第二个绑定也不成功。 I tried using the credentials I use to the second bind in the first one to make sure it worked, and sure enough it can bind it at the first one. 我尝试使用对第一个绑定中的第二个绑定使用的凭据来确保它可以正常工作,并确保它可以在第一个绑定中将其绑定。 Why am I not being able to bind the second time? 为什么我第二次不能绑定?
<?php
// Define $myusername and $mypassword
$username=$_POST['username'];
$password=$_POST['password'];
// using ldap bind
$ldaprdn = 'uid=MYUID,ou=special,ou=people,o=myo.com,dc=mydc,dc=com'; // ldap rdn or dn
$ldappass = 'PASSWORD'; // associated password
// connect to ldap server
$ldapconn = ldap_connect("ldaps://MYLDAPSERVER", ###)
or die("Could not connect to LDAP server.");
if ($ldapconn)
{
// binding to ldap server
$ldapbind = ldap_bind($ldapconn, $ldaprdn, $ldappass);
// verify binding
if ($ldapbind)
{
$result = ldap_search($ldapconn, "ou=people,o=myo.com,dc=mydc,dc=com", "uid=$username");
$info = ldap_get_entries($ldapconn, $result);
$userdn = $info[0]["dn"];
$count = $info["count"];
ldap_unbind($ldapconn);
if ($count == 1)
{
$ldapbinduser = ldap_bind($ldapconn, $userdn, $password);
if ($ldapbinduser)
{
echo "Sucess you made it all the way<br />";
}
else
{
echo "Invalid Login Details, please try again(1001)";
}
}
else
{
echo "Invalid Login Details, please try again(1002)";
}
}
else
{
echo "LDAP bind failed(1000)";
}
}
Although its name might implicate something different, ldap_unbind()
actually kills the connection handle so that the connection is not usable any more after an unbind. 尽管其名称可能暗示了不同的含义,但ldap_unbind()
实际上会ldap_unbind()
连接句柄,因此在取消绑定后该连接将不再可用。 Remove the ldap_unbind()
call from your code and everything should work as expected. 从您的代码中删除ldap_unbind()
调用,一切都会按预期工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.