• PHP ADLogin


    <?php
    
        $user = 'aaaa';
        $password = 'xxxx';
    
        $domain = 'b.a.com'; //设定域名
        $port = 3268;
        $basedn = 'dc=b,dc=a,dc=com'; //如果域名为“b.a.com”,则此处为“dc=b,dc=a,dc=com”
        $filter = "(SAMAccountName=aaaa)";
        $attr = array("thumbnailphoto");
    
        $conn = ldap_connect ( $domain,$port ) or die ( 'Could not connect to LDAP server.' );
       
        $bind = @ldap_bind ( $conn, "{$user}@{$domain}", $password ) or die ( 'Authorization failed! Please check your username or password!' );       
          
        if( $bind )
        {    
            $result = @ldap_search( $conn, $basedn, $filter, $attr);
            // retrieve all the entries from the search result
            $info = ldap_get_entries( $conn, $result );
                 
            $entry = ldap_first_entry($conn,$result);       
        }
        else
        {
            echo 'error<br>';
            echo ldap_error( $conn );
            exit;
        }
        #print_r($info);
        
        if( $info)
        {
            $values = @ldap_get_values_len($conn, $entry, "thumbnailPhoto");
            
            echo '<img src="'.data_uri($values[0], 'image/png').'">';
            
            if(!$values) {           
                
                echo "no thumbnail photo<br>";
            }
     
            // Add the user’s department name and email address
            // to the session
            echo $info[0]['thumbnailPhoto'][0];
            
            foreach($info as $k => $v)  
            {    
                  echo $v['cn'][0]."<br>" ;
                  echo $v['displayname'][0]."<br>" ;
                  echo $v['mail'][0]."<br>" ;  
                  echo $v['department'][0]."<br>" ;
                  echo $v['company'][0]."<br>" ;
                  echo $v['streetaddress'][0]."<br>" ;
                  echo $v['countryCode'][0]."<br>" ;
                  echo $v['userPrincipalName'][0]."<br>" ;
                  echo $v['manager'][0]."<br>" ;
                  echo $v['sn'][0]."<br>" ;
                  echo $v['pwdLastSet'][0]."<br>" ;
                  echo $v['postalCode'][0]."<br>" ;
                  echo $v['title'][0]."<br>" ;
                  echo $v['thumbnailPhoto'][0]."<br>" ;
                  echo $v['location'][0]."<br>" ;
           } 
             
        }
        else
        {
            echo ldap_error($conn);
            exit;
        }
    
        // close connection to ldap server
        $ldap_close( $conn );
        
        function data_uri($file, $mime) {  
            $base64   = base64_encode($file); 
            return ('data:' . $mime . ';base64,' . $base64);
        }
    ?>
  • 相关阅读:
    [手游项目2]-25-linux 端口time_wait
    [手游项目2]-24-linux MySql编译安装
    诛仙手游法宝铸元性价比
    法宝精进性价比对比
    [手游项目2]-23-游戏数据存储解决方案
    [手游项目2]-22-lua内存问题
    [手游项目2]-21-死循环排查
    [手游项目2]-20-mysql还原一个库的部分数据
    [手游项目2]-19-EError=1118, Reason=Row size too large (> 8126)
    bzoj1471
  • 原文地址:https://www.cnblogs.com/zhangchenliang/p/3935586.html
Copyright © 2020-2023  润新知