测试用的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 );
?>

解决方案 »

  1.   

    怎么一到晚上看到的全是招PHP兼职的问题,每一个解决问题的?
    不过也好,看来PHP的需求还是蛮大的:)
      

  2.   

    没用过LDAP,只能友情支持了。
      

  3.   

    首先确定,你的服务器上是有数据的?我看你的过滤器$filter,你确定写的准确么?
      

  4.   

    是正则表达式吗? 那$filter的写法是不对的哦
      

  5.   

    服务器上信息都是有的 我创建了1000多个用户。
    这个filter 其实可以脱掉外面的括号和|的,但是都没取到数据。
    不知道大家有没有现成可用的代码。网上的代码我收集了很多,就那么几种,都没成功,郁闷。
      

  6.   

    感谢庆亮的帮助。原来我的程序少设置了一个参数:)
    <?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) "[email protected]"
        }
        [0]=>
        string(4) "mail"
        ["count"]=>
        int(1)
        ["dn"]=>
        string(34) "CN=uutest,CN=Users,DC=xxx,DC=com"
      }
    }
      

  7.   

    $filter   = "(|(sAMAccountName=*))";//这个过滤条件使用也没问题
      

  8.   

    非常不错的帖子,继续顶一下。对以后有机会了解LDAP埋伏一下,呵呵