请教ldap_search()取不到数据的问题

ttm1984 2009-07-10 04:45:44
测试用的Windows AD服务器 IP:192.168.254.106(testad.com)
真实机192.168.8.2运行php程序。
经测试LDAP连接和绑定都成功了,但是就是搜索不到数据。
请大家帮忙看看什么问题。
谢谢。

<?php

//1.配置信息
// $ldap_server = "testad.com";
$ldap_server = "192.168.254.106";
$ldap_admin = "uutest";
$ldap_password = "uutestpassword";
$base_dn = "dc=testad,dc=com";

//2.连接LDAP服务器器
$conn = ldap_connect ( $ldap_server );
if (! $conn) die ( "Connection LDAP server error\r\n" );

//3.设置参数
ldap_set_option ( $conn, LDAP_OPT_PROTOCOL_VERSION, 3 );

//4.绑定
$bind = ldap_bind ( $conn, $ldap_admin, $ldap_password );
if (! $bind) die ( "Bind LDAP server error\r\n" );

//5.搜索LDAP
$filter = "(|(sAMAccountName=*))";
$result = ldap_search ( $conn, $base_dn, $filter );
$info = ldap_get_entries ( $conn, $result );

var_dump($info);//

// array(1) {
// ["count"]=>
// int(0)
// }
// 这个结果无法接受,请大家帮忙看看为什么没有搜索到值

if (! $result) die ( "Search failed\r\n" );
if ($info ["count"] != 0) echo $info ["count"];

//6.断开连接
ldap_close ( $conn );
?>

...全文
515 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
ruanchao 2009-07-15
  • 打赏
  • 举报
回复
非常不错的帖子,继续顶一下。

对以后有机会了解LDAP埋伏一下,呵呵
ttm1984 2009-07-15
  • 打赏
  • 举报
回复
$filter   = "(|(sAMAccountName=*))";

//这个过滤条件使用也没问题
ttm1984 2009-07-15
  • 打赏
  • 举报
回复
感谢庆亮的帮助。原来我的程序少设置了一个参数:)


<?php

//1.配置信息
$ldap_server = "xxx.com";
$ldap_admin = "administrator";
$ldap_password = "123456";
$base_dn = "dc=xxx,dc=com";

//2.连接LDAP服务器器
$conn = ldap_connect ( $ldap_server );
if (! $conn ) die ( "Connection LDAP server error\r\n" );

//3.设置参数
ldap_set_option ( $conn, LDAP_OPT_PROTOCOL_VERSION, 3 );
ldap_set_option ( $conn, LDAP_OPT_REFERRALS, 0 ); //原来程序这个参数没有设置


//4.绑定
$bind = ldap_bind ( $conn, $ldap_admin, $ldap_password );
if ( !$bind ) die ( "Bind LDAP server error\r\n" );

//5.搜索LDAP
$filter = "(sAMAccountName=uutest)";
$attr = array('mail');
$result = ldap_search ( $conn, $base_dn, $filter, $attr);
$info = ldap_get_entries ( $conn, $result );

if ( !$result ) die ( "Search failed\r\n" );
if ( $info ["count"] != 0 ) {
var_dump($info);
}

//6.断开连接
ldap_close ( $conn );
?>


D:\PHPnow-1.5.3\php-5.2.9-2-Win32>php.exe ldap.php
array(2) {
["count"]=>
int(1)
[0]=>
array(4) {
["mail"]=>
array(2) {
["count"]=>
int(1)
[0]=>
string(16) "uutest@xxx.com"
}
[0]=>
string(4) "mail"
["count"]=>
int(1)
["dn"]=>
string(34) "CN=uutest,CN=Users,DC=xxx,DC=com"
}
}

lonelyriver 2009-07-11
  • 打赏
  • 举报
回复
……
ttm1984 2009-07-11
  • 打赏
  • 举报
回复
服务器上信息都是有的 我创建了1000多个用户。
这个filter 其实可以脱掉外面的括号和|的,但是都没取到数据。
不知道大家有没有现成可用的代码。

网上的代码我收集了很多,就那么几种,都没成功,郁闷。
应该网 2009-07-11
  • 打赏
  • 举报
回复
没用过LDAP,只能友情支持了。
残剑无弦 2009-07-11
  • 打赏
  • 举报
回复
是正则表达式吗? 那$filter的写法是不对的哦
ruanchao 2009-07-11
  • 打赏
  • 举报
回复
首先确定,你的服务器上是有数据的?

我看你的过滤器$filter,你确定写的准确么?
tfxg 2009-07-11
  • 打赏
  • 举报
回复
查不到数据一般是参数错了
ttm1984 2009-07-10
  • 打赏
  • 举报
回复
怎么一到晚上看到的全是招PHP兼职的问题,每一个解决问题的?
不过也好,看来PHP的需求还是蛮大的:)

21,886

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧