PHP Conference Japan 2024

LDAP 函數

目錄

新增筆記

使用者貢獻筆記 34 筆筆記

24
idbobby at rambler dot ru
14 年前
首先,很抱歉我的英文不好。
以下是兩個檢查群組成員資格的函數,以及其他一些對使用 LDAP (在此範例中為 Active Directory) 可能有用的函數。

index.php
---------

<?php

$user
= 'bob';
$password = 'zhlob';
$host = 'myldap';
$domain = 'mydomain.ex';
$basedn = 'dc=mydomain,dc=ex';
$group = 'SomeGroup';

$ad = ldap_connect("ldap://{$host}.{$domain}") or die('無法連線至 LDAP 伺服器。');
ldap_set_option($ad, LDAP_OPT_PROTOCOL_VERSION, 3);
ldap_set_option($ad, LDAP_OPT_REFERRALS, 0);
@
ldap_bind($ad, "{$user}@{$domain}", $password) or die('無法繫結至 AD。');
$userdn = getDN($ad, $user, $basedn);
if (
checkGroupEx($ad, $userdn, getDN($ad, $group, $basedn))) {
//if (checkGroup($ad, $userdn, getDN($ad, $group, $basedn))) {
echo "您已授權為 ".getCN($userdn);
} else {
echo
'授權失敗';
}
ldap_unbind($ad);

/*
* 此函式會在 LDAP 樹狀結構中搜尋 ($ad - LDAP 連線識別碼)
* 由 samaccountname 指定的條目,並在失敗時傳回其 DN 或空字串。
*/
function getDN($ad, $samaccountname, $basedn) {
$attributes = array('dn');
$result = ldap_search($ad, $basedn,
"(samaccountname={$samaccountname})", $attributes);
if (
$result === FALSE) { return ''; }
$entries = ldap_get_entries($ad, $result);
if (
$entries['count']>0) { return $entries[0]['dn']; }
else { return
''; };
}

/*
* 此函式會從給定的 DN 擷取並傳回 CN
*/
function getCN($dn) {
preg_match('/[^,]*/', $dn, $matchs, PREG_OFFSET_CAPTURE, 3);
return
$matchs[0][0];
}

/*
* 此函式會檢查使用者是否為群組成員,僅在指定的群組中搜尋 (不會遞迴)。
*/
function checkGroup($ad, $userdn, $groupdn) {
$attributes = array('members');
$result = ldap_read($ad, $userdn, "(memberof={$groupdn})", $attributes);
if (
$result === FALSE) { return FALSE; };
$entries = ldap_get_entries($ad, $result);
return (
$entries['count'] > 0);
}

/*
* 此函式會檢查使用者是否為群組成員,在指定的群組及其成員群組中搜尋 (遞迴)。
*/
function checkGroupEx($ad, $userdn, $groupdn) {
$attributes = array('memberof');
$result = ldap_read($ad, $userdn, '(objectclass=*)', $attributes);
if (
$result === FALSE) { return FALSE; };
$entries = ldap_get_entries($ad, $result);
if (
$entries['count'] <= 0) { return FALSE; };
if (empty(
$entries[0]['memberof'])) { return FALSE; } else {
for (
$i = 0; $i < $entries[0]['memberof']['count']; $i++) {
if (
$entries[0]['memberof'][$i] == $groupdn) { return TRUE; }
elseif (
checkGroupEx($ad, $entries[0]['memberof'][$i], $groupdn)) { return TRUE; };
};
};
return
FALSE;
}

?>
10
oscar dot php at linaresdigital dot com
9 年前
關於 accountExpires、pwdLastSet、lastLogon 和 badPasswordTime Active Directory 欄位,有很多混淆之處。

它們全部都使用「間隔」日期/時間格式,其值代表自 1601 年 1 月 1 日 (UTC) 以來的 100 奈秒間隔數 (值為 0 或 0x7FFFFFFFFFFFFFFF,即 9223372036854775807,表示帳戶永不過期):https://msdn.microsoft.com/en-us/library/ms675098(v=vs.85).aspx

因此,如果您需要將它從/轉換為 UNIX 時間戳記,您可以輕鬆地計算差異,如下所示:

<?php
$datetime1
= new DateTime('1601-01-01');
$datetime2 = new DateTime('1970-01-01');
$interval = $datetime1->diff($datetime2);
echo (
$interval->days * 24 * 60 * 60) . " 秒\n";
?>

兩個日期之間的差異為 11644473600 秒。不要依賴浮點數計算或其他可能計算錯誤的數字 (包括時區或類似的內容)。

現在您可以從 LDAP 欄位轉換:

<?php
$lastlogon
= $info[$i]['lastlogon'][0];
// 除以 10,000,000 以從 100 奈秒間隔取得秒數
$winInterval = round($lastlogon / 10000000);
// 從 1601-01-01 中減去秒數 -> 1970-01-01
$unixTimestamp = ($winInterval - 11644473600);
// 以本地時區顯示日期/時間
echo date("Y-m-d H:i:s", $unixTimestamp) ."\n";
?>

希望這對您有所幫助。
3
maykelsb at yahoo dot com dot br
17 年前
W2k3 中 ldap_search 的問題,可以透過新增以下程式碼來解決:

// -- $conn 是一個有效的 LDAP 連線。

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

在 ldap_bind 之前,如 http://bugs.php.net/bug.php?id=30670. 中所述。
3
gcathell at thetdgroup dot com
18 年前
我最近需要使用 PHP 通過 SSL 以 LDAP 服務的方式存取 Microsoft Active Directory 伺服器。我花費了很長的時間才找到所有需要的資訊,讓它能正常運作。

我嘗試在這裡發布一篇包含詳細資訊的筆記,但最後因為內容太長而無法張貼。我已將詳細資訊放在以下網址,希望能幫助到其他人,讓他們能夠比我更快地解決問題。

http://greg.cathell.net/php_ldap_ssl.html

祝你好運!
4
spam2004 at turniton dot dk
20 年前
這裡有兩個小函式,可讓您將 Microsoft AD 中的二進制 objectSID 轉換為更有用的文字版本 (格式為 (S-1-5.....))。

// 將小端序的十六進位數字轉換為 'hexdec' 可以轉換的數字
function littleEndian($hex) {
for ($x=strlen($hex)-2; $x >= 0; $x=$x-2) {
$result .= substr($hex,$x,2);
}
return $result;
}

// 傳回文字 SID
function binSIDtoText($binsid) {
$hex_sid=bin2hex($binsid);
$rev = hexdec(substr($hex_sid,0,2)); // 取得 SID 的版本部分
$subcount = hexdec(substr($hex_sid,2,2)); // 取得子授權項目的計數
$auth = hexdec(substr($hex_sid,4,12)); // SECURITY_NT_AUTHORITY
$result = "$rev-$auth";
for ($x=0;$x < $subcount; $x++) {
$subauth[$x] = hexdec(littleEndian(substr($hex_sid,16+($x*8),8))); // 取得所有 SECURITY_NT_AUTHORITY
$result .= "-".$subauth[$x];
}
return $result;
}

echo binSIDtoText($bin_sid);
1
hijinio at comcast dot net
19 年前
如果有人在 Solaris 10 系統上設定 PHP 的 LDAP 支援時遇到問題,以下是我使用的設定行

./configure --with-nsapi=/opt/SUNWwbsvr --enable-libgcc --disable-libxml --with-ldap=/usr/local --prefix=/opt/php/php-5.0.4

需要注意的是 --with-ldap= 使用的位置;對於大多數 S10 的使用者而言,將會是 "--with-ldap=/usr/local"。
1
Richie Bartlett(at)ITsystems-Online com
19 年前
這是對 <i>wtfo at technocraft dot com</i> (2002 年 5 月 23 日 03:40) 的更新... 此函式允許額外的(可選)參數。先前列出的函式在成功驗證後未能關閉 ldap 連線。

<?php
function checkNTuser($username,$password,$DomainName="myDomain",
$ldap_server="ldap://PDC.example.net"){//v0.9
// 當使用者/密碼啟用繫結到 LDAP (Windows 2k) 時傳回 true。
$auth_user=$username."@".$DomainName;
#echo $auth_user."->";
if($connect=@ldap_connect($ldap_server)){
#echo "connection ($ldap_server): ";
if($bind=@ldap_bind($connect, $auth_user, $password)){
#echo "true <BR>";
@ldap_close($connect);
return(
true);
}
//如果繫結到 ldap
}//如果連線到 ldap
#echo "failed <BR>";
@ldap_close($connect);
return(
false);
}
//結束函式 checkNTuser
?>
1
ant at solace dot mh dot se
20 年前
當使用 LDAP 時,值得注意的是,大多數
LDAP 伺服器會將字串編碼為 UTF-8。這對於
非 ASCII 字串而言,表示您將需要在為 LDAP 伺服器建立篩選器時使用 utf8_encode 和
utf8_decode 函式。

當然,如果可以,最好避免使用非 ASCII 字元
但是對於大多數網站而言,使用者喜歡看到他們的特殊原生字元
集,包括母音變音等。

如果您期望看到非 ASCII 字元的地方只出現 ? 字元,那麼
您可能只需要升級您的 PHP 版本。
2
christopherbyrne at hotmail dot com
19 年前
對於在閱讀以下文章後,在處理 Active Directory 中的「accountexpires」屬性時遇到問題的任何人

www.microsoft.com/technet/scriptcenter/
resources/qanda/sept05/hey0902.mspx

或類似的文章,這可能會為您省去一些挫折。文章中提到,此屬性是一個整數,表示自 1601 年 1 月 1 日 00:00:00 以來的奈秒數。

但是,「accountexpires」屬性實際上似乎是自 1600 年 12 月 31 日 14:00:00 以來的 100 奈秒增量數。因此,如果您將該整數除以 10,000,000 並減去 11644560000,您將獲得一個與 AD 中的日期匹配的 Unix 時間戳記。

要設定「accountexpires」日期,只需反向操作即可,也就是說,取得您想要的新日期的時間戳記,加上 11644560000 並乘以 10,000,000。您還需要格式化產生的數字,以確保它不會以科學記號輸出,讓 AD 可以正確處理。

希望這有幫助!
2
llurovi at gmail dot com
8 年前
對於那些在使用者的密碼包含特殊字元時遇到問題的人,請務必將字串解碼為適當的編碼。例如,我遇到一個問題,有些使用者無法正確登入我們的 Web 應用程式。

簡單連線範例

<?php

$ldap_ip
= 'LDAP-SERVER-IP';
$ldap = ldap_connect($ldap_ip);

$user = 'Test';
$password = 'otoño'; //此密碼是正確的,但以此格式繫結會產生錯誤

$password = utf8_decode($password); //$password = otoxF1o

$ldap_bind = ldap_bind($ldap, $user, $password); //現在繫結成功,且 $ldap_bind = true

?>
2
unroar at gmail dot com
17 年前
在 Solaris 9 中,libnet 函式庫是使用 LDAP、SASL 和 SSL 建置 PHP 的先決條件 (libnet 可在 Sunfreeware 上取得)。

我沒有在任何地方看到這點被提及,而且我不確定它是 ldap、sasl 還是 ssl 所需的。我花了一個小時在 Google 上搜索無果,才弄清楚,也許這條評論可以幫助下一個 Google 使用者。

錯誤訊息為,
ld: fatal: library -lnet: not found
ld: fatal: File processing errors. No output written to sapi/cli/php
collect2: ld returned 1 exit status
make: *** [sapi/cli/php] Error 1
1
alex at netflex dot nl
17 年前
如果您想在 Windows 上使用 ldaps,但又不想驗證 tls 憑證,請在 ldap_connect 呼叫之前嘗試以下行

putenv('LDAPTLS_REQCERT=never') or die('設定環境失敗');
2
jabba at zeelandnet dot nl
20 年前
當在 Windows 上使用 PHP 時,如果您嘗試連線(繫結)到需要安全連線 (LDAPS) 的 Netware (6) LDAP 伺服器,PHP 會傳回一則訊息,指出找不到伺服器。

連線嘗試時發生的網路流量擷取顯示,伺服器會提供一個用於 SSL 連線的憑證,但此憑證被用戶端拒絕 (***bad certificate SSLv3 packet)。

造成這種情況的原因可能是 PHP LDAP 實作嘗試使用頒發憑證的 CA 來驗證收到的憑證。可能可以讓驗證成功,但也可以透過建立 openldap(驚喜!!)設定檔來停用用戶端(在本例中為 PHP)的驗證。

此設定檔的位置似乎是硬編碼在 Windows 的 LDAP 支援模組中,您可能需要手動建立以下目錄結構

C:\openldap\sysconf\

在 sysconf 資料夾中,建立一個名為 'ldap.conf' 的文字檔(您可以使用記事本),並且為了停用憑證驗證,請將以下行放入 ldap.conf 檔案中

TLS_REQCERT never

在此之後,所有正常的 ldap_bind 呼叫都會正常運作,前提是您提供的使用者 ID 和密碼正確。
1
Sami Oksanen
20 年前
我編輯了 Jon Caplinger 的程式碼,該程式碼位於下方 (日期:2002 年 11 月 9 日 05:44)。

- 我修正了以下行
"if (!($connect=@ldap_connect($ldap))) {" 為
"if (!($connect=@ldap_connect($ldap_server))) {"

- 移除 $name 屬性

- "Name is:" 欄位始終是一個陣列,因此我將列印行變更為
" echo "Name is: ". $info[$i]["name"][0]."<br>";"

我也新增了一些替代的搜尋篩選器以供嘗試。

以下為程式碼

<?php

$ldap_server
= "ldap://foo.bar.net";
$auth_user = "user@bar.net";
$auth_pass = "mypassword";

// 設定要搜尋整個目錄的 base dn。

$base_dn = "DC=bar, DC=net";

// 只顯示使用者人員
$filter = "(&(objectClass=user)(objectCategory=person)(cn=*))";

// 啟用此設定僅顯示使用者
// $filter = "(&(objectClass=user)(cn=$*))";

// 啟用此設定顯示所有內容
// $filter = "(cn=*)";

// 連接到伺服器

if (!($connect=@ldap_connect($ldap_server))) {
die(
"無法連接到 ldap 伺服器");
}

// 繫結到伺服器

if (!($bind=@ldap_bind($connect, $auth_user, $auth_pass))) {
die(
"無法繫結到伺服器");
}

//if (!($bind=@ldap_bind($connect))) {
// die("無法繫結到伺服器");
//}

// 搜尋 Active Directory

if (!($search=@ldap_search($connect, $base_dn, $filter))) {
die(
"無法搜尋 ldap 伺服器");
}

$number_returned = ldap_count_entries($connect,$search);
$info = ldap_get_entries($connect, $search);

echo
"傳回的項目數量是 ". $number_returned."<p>";

for (
$i=0; $i<$info["count"]; $i++) {
echo
"名稱是: ". $info[$i]["name"][0]."<br>";
echo
"顯示名稱是: ". $info[$i]["displayname"][0]."<br>";
echo
"電子郵件是: ". $info[$i]["mail"][0]."<br>";
echo
"電話號碼是: ". $info[$i]["telephonenumber"][0]."<p>";
}
?>
2
ben_demott at hotmail dot com
16 年前
對於任何程式設計師,如果不太熟悉 Microsoft Active Directory 中的命名慣例,或如何在目錄中尋找物件,更重要的是如何參考這些物件。
從命令列執行 "adsiedit.msc" 將會在目錄中以易於閱讀和複製的命名格式顯示您的所有物件。
希望這對您有所幫助!

注意
您必須從 AD 網域控制站執行此命令
您必須安裝 Windows Resource Kit Tools
(不允許我建立那麼長的連結,所以我必須中斷連結 - 抱歉!)
a http://www.microsoft.com/downloads/details.aspx
?FamilyID=9d467a69-57ff-4ae7-96ee-b18c4790cffd&displaylang=en

安裝此工具應該會修改您的系統路徑,所以您可以直接從執行對話方塊輸入命令,否則絕對路徑是
C:\Program Files\Windows Resource Kits\Tools\adsiedit.msc
2
nacenroe at remove dot this dot nystec dot com
18 年前
如果您想要使用 PHP 將 LDAP 與 AD 整合(我正在使用 Win2K3),您可能會想要試用 Win2k 和 Win2K3 隨附的 LDP.exe 工具(不需要資源套件!!)。您可以直接從命令列執行此應用程式。

Win2K3 說明功能是一個很好的起點,然後它將我指向 M$ KB 中的一篇文章:http://support.microsoft.com/default.aspx?scid=kb;en-us;255602 (XADM:使用 LDP 公用程式進行瀏覽和查詢)。

因此...如果您的連線/繫結都正常,但您的查詢不正常,您可能需要從這裡開始。我發現當我在本機 AD 上執行它時,它對於查看屬性等非常有幫助。
2
christopherbyrne at hotmail dot com
19 年前
只是對我之前文章的修正:我的計算使用的是澳洲東岸時間 (GMT+10),而 Unix 時間戳記是以 GMT 為單位。因此,Active Directory 的 "accountexpires" 整數值確實是從 1601 年 1 月 1 日 00:00:00 GMT 開始,而此日期與 1970 年 1 月 1 日 00:00:00 GMT 之間相隔的秒數為 11644524000。

不過,增量仍然絕對是以 100 奈秒為單位!
2
jpmens at gmail dot com
19 年前
關於 jabba at zeelandnet dot nl 的說明。如果您嘗試使用 OpenLDAP 連線到 LDAPS URI,您可以按照 jabba 的說明建立設定檔,或者,使用環境設定將 LDAPTLS_REQCERT=never 設定為 ldap.conf(5) 中所述。
2
knitterb at blandsite dot org
22 年前
當使用 PHP 4.2.1 與 OpenLDAP 2.1.2 時,我遇到繫結到 ldap 伺服器的問題。我發現 php 使用的是較舊的通訊協定,並將以下內容新增至 slapd.conf

allow bind_v2

請參閱 ``man slapd.conf'',以取得關於 slapd.conf 檔案中 allow 項目的詳細資訊,這就是我所知道的全部!:)
1
Jimmy Wimenta Oei
20 年前
如果您想要停用/啟用追蹤參照選項,您需要先將通訊協定版本設定為版本 3,否則 LDAP_OPT_REFERRALS 選項將不會有任何效果。對於查詢 MS Active Directory 尤其如此。

<?php
ldap_set_option
($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
ldap_set_option($ds, LDAP_OPT_REFERRALS, 0);
?>

一如既往,這些應該在連線之後但在繫結之前呼叫。
0
Andrew Sharpe
12 年前
若要在 RHEL 6.2 x86_64 上編譯 PHP 5.1.6,請將以下內容新增至您的 configure 命令

--with-libdir=lib64
--with-ldap=/usr
1
pookey at pookey dot co dot uk
21 年前
這是一個如何查詢 LDAP 伺服器,並印出所有項目的範例。

<?php

$ldapServer
= '127.0.0.1';
$ldapBase = 'DC=anlx,DC=net';

/*
* 嘗試連線到伺服器
*/
$ldapConn = ldap_connect($ldapServer);
if (!
$ldapConn)
{
die(
'無法連線到 LDAP 伺服器');
}

/*
* 匿名綁定
*/
$ldapBind = ldap_bind($ldapConn);
if (!
$ldapBind)
{
die(
'無法綁定到 LDAP 伺服器');
}

/*
* 設定 LDAP 選項
*/
ldap_set_option($ldapConn, LDAP_OPT_PROTOCOL_VERSION, 3);

/*
* 搜尋 LDAP 伺服器
*/
$ldapSearch = ldap_search($ldapConn, $ldapBase, "(cn=*)");
$ldapResults = ldap_get_entries($ldapConn, $ldapSearch);

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

?>
1
greatsafari at hotmail dot com
21 年前
看過這麼多種連線和查詢 Active Directory 伺服器的方法,我真的開始懷疑整個過程是否取決於 Active Directory 的組態。看看這篇文章:

http://www.phpbuilder.com/mail/php-general/2003022/1459.php

某些方法在某個實例中證明有效,但在另一個實例中卻失敗了。
1
nliu99 at nospam dot yahoo dot com
21 年前
ldap 功能**不**需要 libsasl.dll。請查看以下文章:http://bugs.php.net/bug.php?id=9485

在 Win2k 上,我按照這些簡單的步驟使 ldap 正常運作
1. 將 php_ldap.dll 從 extension 資料夾複製到 winnt/system32
2. 編輯 winnt/php.ini,啟用 ldap (取消註解該行)。
3. 重新啟動 IIS。
就是這樣,好好享受 ldap 吧。

Microsoft Active Directory 的注意事項
1. 您可以使用使用者電子郵件登入,例如 user@company.com
2. 使用 ldap_search 過濾 (userprincipalname=[user]) 來搜尋使用者資訊最簡單。
1
egeczi at nospamplease dot dist113 dot org
21 年前
在執行 IIS 的 Win2k Server 上,僅在啟用 php_ldap 擴充功能後重新啟動 IIS 是不夠的。您必須重新啟動伺服器本身。
1
yorch at correo dot ath dot cx
21 年前
關於在 Win2k 電腦上執行 LDAP 擴充功能的一些注意事項

在將 php_ldap.php 和 libsasl.dll 複製到每個可能的目錄 (c:\WinNT\System32, c:\php ...) 後,我決定閱讀 installation.txt 檔案。
安裝 php 擴充功能的說明如下:「某些 PHP 擴充功能需要額外的 DLL。請將套件中 'dlls/' 目錄中的 DLL 複製到您的 windows/system (Win9.x) 或 winnt/system32 (WinNT, Win2000, XP) 目錄。如果您的系統上已安裝這些 DLL,請僅在某些功能無法正常運作時才覆寫它們。」

所以我完全按照說明操作:將「c:\php\dlls」中的所有 dll 檔案複製到「c:\WinNT\System32」。
現在它們可以完美載入了 ;-)

我希望這對某些人有幫助。
0
Tod
17 年前
針對在 Win2k3 上使用 Apache 2.2 執行 PHP 4 的人員的注意事項。
Apache 服務需要在本機管理員帳戶下執行,ldap_connect 才能傳回結果。而不是在 Active Directory 網域中的伺服器上可能發生的網域管理員帳戶。

它會「看起來」可以正常運作,但否則會傳回沒有結果。

因此,請在服務登入屬性中使用 (伺服器名稱)\administrator 作為使用者名稱。

Tod
0
jector at inbox dot ru
17 年前
花了一些時間修正「無法載入動態程式庫 'php_ldap.dll'」。到處複製了 libeay32.dll 和 ssleay32.dll,但錯誤仍然存在。

在研究了所有這些 dll 後,我發現 libeay32.dll 和 ssleay32.dll 都需要 msvcr70.dll (或 msvcr71.dll,取決於編譯器版本)。然後,只需將該 dll 複製到 system32\ 目錄,它就可以完美運作了。
0
nigelf at esp dot co dot uk
18 年前
在 Active Directory 中追蹤參照 (例如:跨網域搜尋) 可能會很慢。您可以改為在 GC (全域編錄) 中查閱物件,如下所示

當您使用 ldap_connect 時,請移除任何對 ldap:// 的參照,例如:使用 "serv1.mydom.com" 而**不**是 "ldap://serv1.mydom.com"

連線到 3268 埠 (而不是預設的 389)

將搜尋的 Base DN 設定為 null,例如:"" (空引號)。

然後 AD 將針對保存樹系中所有物件副本的 GC 執行搜尋。您還可以擷取屬性的子集 (包括群組成員資格,但本機群組除外)。

您仍然需要追蹤參照才能取得完整的屬性集。
0
hkemale at hkem dot com
21 年前
適用於 IIS+PHP+NTFS 檔案系統使用者
將 <php_dir>/dlls/*.dll 複製到 <windows>/systems32/ 後,請記住新增「everyone」和副檔名 *.dll 的讀取和執行權限。這可以防止 php_ldap.dll 的存取被拒絕警告。
0
gerbille at free dot fr
22 年前
PHP 的 MD5 傳回以 base16 編碼的結果。但 LDAP MD5 傳回以 base64 編碼的字串。
$pwd="toto";
$pwd_md5=base64_encode(mhash(MHASH_MD5,$pwd));
只需在 $pwd_md5 前面新增 "{MD5}" 即可取得與 LDAP 目錄相同的格式。

再見
Aur?lia
0
mike at whisperedlies dot org
22 年前
除了上述 netBIOS 建議外,當繫結到 Windows2k AD 伺服器時,您可以使用目標使用者的 UPN。例如,如果您的 SAM 帳戶名稱是 firstname.lastname,而您的網域是 domainname.com,則您的 UPN 可能是 firstname.lastname@domainname.com

這可用於繫結到 AD。我沒有看到任何方法有任何差異。
0
rusko dot marton at gibzone dot hu
22 年前
您可以使用簡化的 netbios 格式的使用者名稱,輕鬆地驗證 Windows 2000 網域的 ldap 伺服器。

有人寫道
當驗證到 Win2k LDAP 伺服器時,人員的名稱必須是
dn 中的完整名稱

不。您可以使用此格式

$user = "網域名稱\\使用者名稱"
$password = "使用者的密碼";

if (!$connect = ldap_connect("<伺服器>", <埠號>)) {
//錯誤
exit;
}
if (!$res = @ldap_bind($ldap, $user, $password)) {
//錯誤
exit;
}

它與 Active Directory 運作良好,我們正在使用它。
0
webmaster at autourdupc dot com
22 年前
當驗證到 Win2k LDAP 伺服器時,人員的名稱必須是 dn 中的完整名稱

注意:任何內容都不區分大小寫!

$dn="cn=DUPOND John, cn=Users, dc=autourdupc, dc=com"
$password = "DUPOND 的密碼";

然後當您繫結到 LDAP 資料庫時,請使用

if (!($ldap = ldap_connect("<伺服器>", <埠號>))) {
die ("無法連線到 LDAP 伺服器");
}
if (!($res = @ldap_bind($ldap, $dn, $password))) {
die ("無法繫結到 $dn");
}

希望這對大家有用!
To Top