iT邦幫忙

0

PHP 查詢AD裡面的資料

  • 分享至 

  • xImage

請問大大

我要透過PHP連結AD去查詢USER資料,可是怎麼都一直撈不到資料,可否協助查看一下,感謝

<?php

$domain = '1234.corp';
$ldaprdn = 'ABC';
$ldappass = '123';

$ldapconn = ldap_connect($domain) or die("無法連接至 $domain");

ldap_set_option($ldapconn, LDAP_OPT_PROTOCOL_VERSION, 3);
ldap_set_option($ldapconn, LDAP_OPT_REFERRALS, 0);

if ($ldapconn) { // binding to ldap server
//    $ldapbind = ldap_bind($ldapconn, $ldaprdn, $ldappass);
    $ldapbind = ldap_bind($ldapconn, $ldaprdn, $ldappass);
    // verify binding
    if ($ldapbind) {
        $filter = "(samaccountname='user')";
        $_dn = str_replace('OU=xxxxx','DC=xxxxx','DC=corp'. $domain);
        $result = ldap_search($ldapconn, $_dn, $filter);

        $info = ldap_get_entries($ldapconn, $result);
        print_r($info);
    } else {
        echo "認證失敗...";
    }
}
?>

輪出結果為下:
Array ( [count] => 0 ) ?>

peggy0808 iT邦新手 5 級 ‧ 2016-09-06 12:09:57 檢舉
<?php

$domain = '1234.corp';
$ldaprdn = '';
$ldappass = '';

$ldapconn = ldap_connect($domain) or die("無法連接至 $domain");

ldap_set_option($ldapconn, LDAP_OPT_PROTOCOL_VERSION, 3);
ldap_set_option($ldapconn, LDAP_OPT_REFERRALS, 0);

if ($ldapconn) { // binding to ldap server
// $ldapbind = ldap_bind($ldapconn, $ldaprdn, $ldappass);
$ldapbind = ldap_bind($ldapconn, $ldaprdn, $ldappass);
// verify binding
if ($ldapbind) {
$filter = "(samaccountname='user')";
$_dn = str_replace('OU=xxxxx','DC=xxxxx','DC=corp'. $domain);
$result = ldap_search($ldapconn, $_dn, $filter);

$info = ldap_get_entries($ldapconn, $result);
print_r($info);
} else {
echo "認證失敗...";
}
}
?>
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

1 個回答

我要發表回答

立即登入回答