html5中文学习网

您的位置: 首页 > 网络编程 > PHP编程 » 正文

php获取ad域用户:PHP 读取 AD 用户_PHP教程_编程技术

[ ] 已经帮助:人解决问题
  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$search); 
  21. if ($entries["count"] > 0) { 
  22. echo '返回记录数:'.$entries["count"]; 
  23. for ($i=0; $i<$entries["count"]; $i++) { 
  24. //所要获取的字段,都必须小写 
  25. if(isset($entries[$i]["displayname"])){ 
  26. echo "<p>displayname: ".$entries[$i]["displayname"][0]."<br />";//用户名 
  27. if(isset($entries[$i]["cn"][0])){ 
  28. echo "cn: ".$entries[$i]["cn"][0]."<br />";//用户名字 
  29. else { 
  30. echo "<p>No results found!</p>"
  31. }else
  32. echo "Unable to connect to AD server"
  33. ?>  
本文链接http://www.cxybl.com/html/wlbc/Php/20130319/37245.html
WPuHTML5中文学习网 - HTML5先行者学习网
WPuHTML5中文学习网 - HTML5先行者学习网
(责任编辑:)
推荐书籍
推荐资讯
关于HTML5先行者 - 联系我们 - 广告服务 - 友情链接 - 网站地图 - 版权声明 - 人才招聘 - 帮助