如何在Codeigniter上集成LDAP Auth


How do i integrate LDAP Auth on Codeigniter?

我目前正在开发一个应用程序,我希望在登录时有一个LDAP Auth。有人能给我提供教程链接吗?或者只是帮我怎么做。我不知道怎么做。

1.设置LDAP服务器。通过阅读您的描述,我认为您已经有了一个。

2.您可以通过这些代码连接您的服务器。我绑定到LDAP并搜索"uniqueMember"属性。

`/**
 *
 */
public static function connLdap(){
    $ldapConfig = Sys::getLdapConfig();//just a config Array
    $ds = ldap_connect($ldapConfig['host']);
    ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
    $loginDn = $ldapConfig['adminDn'];
    $passwd = $ldapConfig['passwd'];
    ldap_bind($ds,$loginDn,$passwd);
    return $ds;
}
public static function getPayEmailsLdap(){
    //getAdministrators
    //Connect to LDAP
    $ds = Sys::connLdap();
    //begin to search,need the resource $ds before.
    $res = ldap_search($ds,"cn=yourAddress","(cn=*)",array("uniqueMember"));
    $resInfo = ldap_get_entries($ds,$res);
    $return = array();
    $pattern = '/cn=(.*?),/';
    foreach ($resInfo[0]['uniquemember'] as $v) {
        preg_match($pattern,$v,$matches);
        if($matches){
            $return[] = $matches[1].'@admin.com';
        }
    }
    return $return;
}

`