日期:2011-08-22  浏览次数:21741 次

  1. <?php 
  2. //phpinfo(); 
  3. $host = "******:389"
  4. $user = "**@**"
  5. $pswd = "*****"
  6. $ad = ldap_connect($hostor die"Could not connect!" ); 
  7. if($ad){ 
  8. //设置参数 
  9. ldap_set_option ( $ad, LDAP_OPT_PROTOCOL_VERSION, 3 ); 
  10. ldap_set_option ( $ad, LDAP_OPT_REFERRALS, 0 ); 
  11. // bool ldap_bind ( resource $link_identifier [, string $bind_rdn = NULL [, string $bind_password = NULL ]] ) 
  12. $bd = ldap_bind($ad$user$pswdor die ("Could not bind"); 
  13. echo "ldap_bind success"
  14. //指定需要获取的用户属性 
  15. $attrs = array("displayname","cn"); 
  16. //指定需查询的用户范围 
  17. $filter = "(objectclass=*)"
  18. //ldap_search ( resource $link_identifier , string $base_dn , string $filter [, array $attributes [, int $attrsonly [, int $sizelimit [, int $timelimit [, int $deref ]]]]] ) 
  19. $search = ldap_search($ad'DC=**,DC=**,DC=**'$filter$attrs,0,0,0) or die ("ldap search failed"); 
  20. $entries = ldap_get_entries($ad