• 技术文章 >php教程 >php手册

    简单的LDAP浏览器php版

    2016-06-13 10:24:15原创383
    这是用PHP写的LDAP浏览器,您可以从这个程序中了解到如何用PHP来访问LDAP.
    if(!isset($host)) $host = localhost;
    if(!isset($port)) $port = 389;
    if(!isset($dn)) $dn = dc=my-domain,dc=com;
    if(!isset($filter)) $filter = objectclass=*;

    $con = ldap_connect($host,$port) or die(ldap_connect error);

    echo
    .chr(13);

    //read this object
    $rst = ldap_read($con,$dn,$filter) or die(ldap_read error);
    $entry = ldap_first_entry($con,$rst) or die(ldap_first_entry error);
    echo $dn.:.chr(13);
    $attrs = ldap_get_attributes($con,$entry);
    $attrs_count = $attrs[count];
    for($i=0;$i<$attrs_count;$i++){
    echo .$attrs[$i].chr(13);
    $values = ldap_get_values($con,$entry,$attrs[$i]);
    $values_count = $values[count];
    for($j=0;$j<$values_count;$j++) echo .$values[$j].chr(13);
    }
    ldap_free_result($rst);

    //get all objects of this entry

    $rst = ldap_list($con,$dn,$filter) or die(ldap_list error);
    $count = ldap_count_entries($con,$rst);
    if($count){
    echo all objects of this entry:--------------------------------------------------------------------------------;
    $entry = ldap_first_entry($con,$rst);
    while($entry){
    $entry_dn = ldap_get_dn($con,$entry);
    echo .$entry_dn..chr(13);
    $entry = ldap_next_entry($con,$entry);
    }
    }
    ldap_free_result($rst);

    ldap_close($con);

    echo 返回.chr(13);

    echo
    .chr(13);
    ?>
    声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。
    上一篇:ZendStudio3.0试用手记 下一篇:自己动手写 PHP MVC 框架(40节精讲/巨细/新人进阶必看)

    相关文章推荐

    • 我的论坛源代码(五)• 使用PHP4.2.0及以后版本的注意事项• php 魔术函数使用说明_php基础• smarty模板引擎从php中获取数据的方法,smarty模板• php利用新浪接口查询ip获取地理位置
    1/1

    PHP中文网