繁体   English   中英

在PHP中使用PEAR LDAP2连接到LDAP

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM