LDAP身份验证-PHP(请帮助)搜索
好的,我已经改变了我以前的代码。我还发现我的开发版本无法正常工作!:/LDAP身份验证-PHP(请帮助)搜索,php,login,ldap,intranet,Php,Login,Ldap,Intranet,好的,我已经改变了我以前的代码。我还发现我的开发版本无法正常工作!:/ 我的新代码构造得更好,但我无法理解LDAP_搜索位,我得到的错误是: 错误: 我的代码: 此客户端连接到的LDAP目录服务器已响应搜索请求,出现操作错误,这是特定的LDAP结果代码。应查阅目录服务器日志,以确定此特定服务器拒绝搜索请求的原因 搜索请求应始终包括大小限制和时间限制,以及是否取消引用别名的概念。当超过大小限制或时间限制时,某些API有生成错误的坏习惯。应该避免使用这些API,但如果PHP是其中之一,请显式指定参
我的新代码构造得更好,但我无法理解LDAP_搜索位,我得到的错误是:
错误: 我的代码:
- 此客户端连接到的LDAP目录服务器已响应搜索请求,出现
操作错误
,这是特定的LDAP结果代码。应查阅目录服务器日志,以确定此特定服务器拒绝搜索请求的原因
- 搜索请求应始终包括大小限制和时间限制,以及是否取消引用别名的概念。当超过大小限制或时间限制时,某些API有生成错误的坏习惯。应该避免使用这些API,但如果PHP是其中之一,请显式指定参数,并检查是否未生成错误以及是否正确报告错误
- 搜索请求将
dn
列为要返回的属性dn
不是属性,它是正在进行搜索的对象的主键。如果LDAP客户端希望从搜索请求返回属性及其值,则必须单独列出属性,否则*
将返回所有用户属性,+
将返回所有操作属性(每个属性都有与其相关联的访问控制,这可能会限制可以检索属性的授权状态)。如果LDAP客户端希望从搜索中不返回属性,则客户端应使用属性列表中的OID1.1
。在这种情况下,服务器将只返回与搜索参数匹配的条目的DNs
另见
ldap\u error($conn\u status)
显示了什么?我将ldap\u error($conn\u status)放在我的代码中,并对其进行了测试和响应,获得了“成功”…这有帮助吗,我是ldap新手…:)嗯,我认为在使用ldap提供用户名时,不能使用空密码。。。请尝试为您的用户设置密码,然后重试。
Warning: ldap_search(): Search: Operations error in C:\inetpub\wwwroot\Intranet\login\index.php on line 34
Search on LDAP failed
<?php
// Application specific LDAP login
$app_user = 'cn=users,dc=DOMAIN, dc=local';
$app_pass = '';
// User-provided info (either from _POST or any way else)
// You should LDAP-escape $username here since it will be
// used as a parameter for searches, but it's not a
// subject of this article. That one will follow soon. :-)
$username = 'USERNAME';
$password = PASSWORD;
// Here we'll put user's DN
$userdn = 'users';
// Connect to LDAP service
$conn_status = ldap_connect('SERVER.DOMAIN.local', 389);
if ($conn_status === FALSE) {
die("Couldn't connect to LDAP service");
}
// Bind as application
$bind_status = ldap_bind($conn_status, $app_user, $app_pass);
if ($bind_status === FALSE) {
die("Couldn't bind to LDAP as application user");
}
// Find the user's DN
// See the note above about the need to LDAP-escape $username!
$query = "(&(uid=" . $username . ")(objectClass=user))";
$search_base = "cn=users,dc=DOMAIN, dc=local";
$search_status = ldap_search(
$conn_status, $search_base, $query, array('dn')
);
if ($search_status === FALSE) {
die("Search on LDAP failed");
}
// Pull the search results
$result = ldap_get_entries($conn_status, $search_status);
if ($result === FALSE) {
die("Couldn't pull search results from LDAP");
}
if ((int) @$result['count'] > 0) {
// Definitely pulled something, we don't check here
// for this example if it's more results than 1,
// although you should.
$userdn = $result[0]['dn'];
}
if (trim((string) $userdn) == '') {
die("Empty DN. Something is wrong.");
}
// Authenticate with the newly found DN and user-provided password
$auth_status = ldap_bind($conn_status, $userdn, $password);
if ($auth_status === FALSE) {
die("Couldn't bind to LDAP as user!");
}
print "Authentication against LDAP succesful. Valid username and password provided.";
?>