2016-06-29 15 views
0

次のLDAPパラメータが送信されましたが、PHPで接続を確立する方法がわかりません。私はどのPHP関数をパラメータの各セットで使うのかよくわかりません。PHP LDAP接続

サーバー: LDAPS://the_server.com:636

ルートDN:ここで私は与えられたパラメータは、 DC = the_info、DC = more_info、dc = comの

ユーザー検索ベース: OU = CompanyUsers

ユーザー検索フィルター:のsAMAccountName = {0}

グループ検索ベース: OU =セキュリティ、OU = CompanyGroups

グループ検索フィルター: CN = {0}

グループメンバーシップ:グループメンバーシップ属性=のmemberOf

ディスプレイ名前LDAP属性: displayname

電子メールアドレスLDAP atribute:メール

誰かが私のために素晴らしいPHPスクリプトを提供することができたら!これは初めてLDAPを使用していても、これらのパラメータをすべて理解できていません。

答えて

0

以下は、linuxベースのldapの作業コードです。 あなたに役立つかもしれません。

<?php 
$username = 'uid=amitkawasthi,ou=CompanyUsers,dc=the_info,dc=more_info,dc=com'; 
$password= 'test'; 
$ds=ldap_connect("the_server.com, 636"); 
echo $ds; 
if ($ds) { 
    echo "Binding ..."; 
    $r=ldap_bind($ds, $username, $password); 
    if ($r) 
    { 
    $sr=ldap_search($ds,"ou=CompanyUsers,dc=the_info,dc=more_info,dc=com", "uid=amitkawasthi"); 
    $entry = ldap_first_entry($ds, $sr); 
    $attrs = array(); 
    $attribute = ldap_first_attribute($ds,$entry,$identifier); 
    while ($attribute) { 
    $attrs[] = $attribute; 
    $attribute=ldap_next_attribute($ds,$entry,$identifier); 
    } 
    echo count($attrs) . " attributes held for this entry:<p>"; 

    $ldapResults = ldap_get_entries($ds, $sr); 
//for ($item = 0; $item < $ldapResults['count']; $item++) { 
    // for ($attribute = 0; $attribute < $ldapResults[$item]['count'];     $attribute++) { 
    //echo $data = $ldapResults[$item][$attribute]; 
    echo $data = $ldapResults[0][$attribute]; 
    echo $data.":&nbsp;&nbsp;".$ldapResults[0][$data][0]."<br>";    
    //} 
///echo '<hr />'; 

    echo "OK"; 
    } 
    else 
    { 
    echo "Fail"; 

    } 
} 

?> 
============================