2013-02-20 13 views
0

我对使用LDAP并不是很有经验,并且一直在研究几个堆栈溢出问题,并试图将一些代码拼凑在一起。在PHP中使用PEAR LDAP2连接到LDAP

我使用PEAR LDAP2包与我的PHP。到目前为止,我已经设置了我的过滤器,但我还没有搜索任何东西。

所有我想要做的是建立我与服务器的连接,但是当我的代码达到:

$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()); 
} 

回答

0

考虑验证的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命令行选项