PHP教學-在 windows 環境底下通過 ldap over ssl 以 xampp 為例

最近被 ldap over ssl 搞到快瘋了,嘗試做了 linux 版 openldap server,也建了 windows server 2012 r2 ad server ,嘗試做了 linux client 去連線 ad server 成功!!,但同樣的設定在windows 環境底下就是搞不定,根據 PHP ldap 函式文件中說明 ldap over ssl 在 windows 環境下需將 ldap.conf 檔建立在 C 磁碟中,路徑為 C:\openldap\sysconf\ldap.conf,當我看到這段話時,誤以為真的要安裝 openldap,然後就真的去下載來安裝,結果 apache 根本沒有讀到,也就是說服務是沒有開啟的,搞了好幾天,被超強的主管跳下來協助研究,發現到這句話式有玄機的,php ldap 函式文件中就已經將 "C:\openldap\sysconf\ldap.conf" 路徑和 ldap.conf 檔案給寫死了,搞了半天原來我只要新增一個 ldap.conf 檔案,放在對應的路徑裡,在檔案中放入
TLS_REQCERT never
就過了!!!
就那麼簡單讓我搞了好幾天!

提供範例程式

<?php

// using ldap bind
$ldaprdn  = 'xxx';     // ad 帳號
$ldappass = '1qaz2WSX';  // ad 密碼

// connect to ldap server
$ldapconn = ldap_connect("ldaps://xxxx.com:636")
    or die("Could not connect to LDAP server."); //此為加密型的 ad 網域
ldap_set_option(NULL, LDAP_OPT_DEBUG_LEVEL, 7);
if ($ldapconn) {

    // binding to ldap server
    $ldapbind = ldap_bind($ldapconn, $ldaprdn, $ldappass);

    // verify binding
    if ($ldapbind) {
        echo "LDAP bind successful...";
    } else {
        echo "LDAP bind failed...";
    }

}


 

留言

這個網誌中的熱門文章

c語言-關於#define用法

CMD常用網管指令

PHP 與 JavaScript 之間傳值利用 json