[英]Connecting to LDAP using PEAR LDAP2 in PHP
我對使用LDAP的經驗不是很豐富,並且一直在研究一些堆棧溢出問題,並嘗試將一些代碼組合在一起。
我的PHP使用的是PEAR LDAP2軟件包。 到目前為止,我已經設置了過濾器,但是我還沒有搜索任何內容。
我要做的就是建立與服務器的連接,但是當我的代碼到達時:
$ldap= Net_LDAP2::connect($config);
該腳本凍結並產生白屏。 我怎樣才能解決這個問題?
腳本如下:
<?php
include '../config/connection.php';
require_once '../Scripts/Net_LDAP2-2.0.12/Net/LDAP2/LDAP2.php';
//retrieve information from the form
$username = $_POST['username'];
$password = $_POST['password'];
$usernamefilter = Net_LDAP2_Filter::create('username', 'equals', $username);
$passwordfilter = Net_LDAP2_Filter::create('password', 'equals', $password);
$combinedFilter = Net_LDAP2_Filter::combine('and', array($usernamefilter, $passwordfilter));
echo "filters have been created. <br />";
// The configuration array:
$config = array (
'binddn' => 'username',
'bindpw' => 'password',
'basedn' => 'ou=People,dc=campus,dc=aston,dc=ac,dc=uk',
'host' => 'gc.campus.aston.ac.uk',
'filter' => $combinedFilter
);
echo "config array has been set up. <br />";
// Connecting using the configuration:
$ldap = Net_LDAP2::connect($config);
echo "connection to ldap has been sent. <br />";
// Testing for connection error
if (PEAR::isError($ldap)) {
die('Could not connect to LDAP-server: '.$ldap->getMessage());
}
考慮使用已知的合格客戶端來驗證LDAP目錄服務器是否正確響應了LDAP客戶端請求。 由供應商分發的ldapsearch
是完成此任務的最佳選擇。 執行以下搜索以確認服務器正在接受連接的客戶端連接並正在響應:
ldapsearch -h gc.campus.aston.ac.uk -p <your-port> \
-D the-distinguished-name -w password \
-b 'ou=People,dc=campus,dc=aston,dc=ac,dc=uk' \
-s base '(&)' 1.1
如果掛起,失敗或不返回任何條目,請更正問題並重新測試,直到上述命令成功。
注意:如果使用的是舊版OpenLDAP ldapsearch,請添加-x命令行選項
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.