• php ldap添加与修改


    /**
     * ldap 备份
     * @param int $cardid    
     * @param string $username 
     * @param string $password 未加密密码
     * @return null
     */
    function ldapBack($cardid,$username,$password){
        $connect = ldap_connect(LDAP_HOST,LDAP_PORT);
        if(!$connect){
            $log = Logger::getLogger();
            $log->fatal('备份LDAP连接失败!');
        }
        ldap_set_option($connect, LDAP_OPT_PROTOCOL_VERSION, 3);
        @$back_bind = ldap_bind($connect, LDAP_ADMIN_USER, LDAP_ADMIN_PW); 
        
        $add_entry = array();
        $add_entry['objectclass'][] = 'top';
        $add_entry['objectclass'][] = 'person';
        $add_entry['objectclass'][] = 'inetOrgPerson';
        $add_entry['cn'] = $username;
        $add_entry['uid'] = $cardid;
        $add_entry['sn'] = $username;
        $add_entry['userpassword'] = "{MD5}".base64_encode(md5($password,true));
        $dn = "uid={$cardid},ou=people,dc=buct,dc=edu,dc=cn";
        
        //查询ldap中是否已经存在相应数据
        $base_dn = "DC=buct,DC=edu,DC=cn";
        $filter = "(uid=$cardid)";
        $read = ldap_search($connect, $base_dn, $filter);
        $info = ldap_get_entries($connect, $read);
        
        if(empty($info['count']))
        {//不存在数据,使用添加方法添加数据
            $boo = ldap_add($connect,$dn,$add_entry);
        }else
        {//数据已经存在,使用编辑方法修改数据
            $boo = ldap_modify($connect,$dn,$add_entry);
        }
        //$boo = ldap_modify($connect,$dn,$add_entry);
        
        ldap_close($connect);
        $_data = array();
        $_data['cardid'] = $info[0]['uid'][0];
        $_data['name'] = $info[0]['sn'][0];
        return $_data;
    }
  • 相关阅读:
    js 计时器小练-20160601
    数位dp入门学习之路(正常枚举“过渡到”dfs枚举)
    An easy problem
    牌型种类 蓝桥杯
    带分数(穷举法) 蓝桥杯赛题
    表达式的转换----->中缀表达式转后缀表达式
    map 的使用
    netsatat 的使用
    两个矩形不相交
    前缀和
  • 原文地址:https://www.cnblogs.com/ccdc/p/2749318.html
Copyright © 2020-2023  润新知