login.php 內容 $domain = "example.com.tw"; // 網域名稱 $ldap_server = "example01"; // AD SERVER 名稱 $connect_ad = ldap_connect ($ldap_server) or die ("無法連線AD SERVER"); ldap_set_option ($connect_ad, LDAP_OPT_PROTOCOL_VERSION, 3); ldap_set_option ($ds, LDAP_OPT_REFERRALS, 0); $ldapbind = @ ldap_bind ($connect_ad, "user01@".$domain, "userPassword"); if ($ldapbind) { echo "驗證成功,已登入"; } else { echo "驗證失敗。"; } ?> 於WEB SERVER執行時,永遠為顯示"驗證失敗"; 但是,以指令執行 [user01@example.com.tw html]$php login.php 其結果為"驗證成功,已登入"。 在 stackOverflow網站上有一篇回答 SELinux doesn't allow your httpd daemon to talk to the LDAP server on the same machine. 所以,我們要變更一下系統設定。 檢查httpd使用配置 getsebool -a | grep httpd httpd_anon_write --> off httpd_builtin_scripting --> on httpd_can_check_spam --> off httpd_can_connect_ftp --> off httpd_can_connect_ldap --> off httpd_can