gpt4 book ai didi

PHP 5.3.5 ldap_search() : Search: Can't contact LDAP server

转载 作者:可可西里 更新时间:2023-10-31 22:14:56 28 4
gpt4 key购买 nike

我有一个 LDAP PHP 类,它适用于我们公司的所有其他 PHP 安装。但是,现在我从 SuSE 更改为 Ubuntu 11.04,代码停止工作。 PHP版本为5.3.5。

我尝试连接到我们的 LDAP 服务器。连接到它后,我尝试运行 ldap_search。它失败并显示错误消息“ldap_search():搜索:无法联系 LDAP 服务器”。我使用 wireshark 查看了流量,可以看到 php 和 ldap 之间正在发生通信,可惜没有发生连接。

感谢您的意见,乌韦

这是我使用的代码:

class ldap{
private $ldap_conn;
private $ldaphost;
private $ldapport;

public function __construct ()
{
$this->ldaphost = 'ldaps://ourserver.co.nz'; // obviously a fake name
$this->ldapport = 636;
$this->ldap_conn = ldap_connect($this->ldaphost, $this->ldapport) or die("Could not connect to $this->ldaphost");
}

public function signin ($username,$password, $applicationName)
{
$dn = "o=MY_COM";
$filter="(cn=$username)";

$justthese = array("dn","fullname", "mail");

$sr=ldap_search($this->ldap_conn, $dn, $filter, $justthese);

$people = ldap_get_entries($this->ldapconn, $sr);

if (!$people || count($people) == 0 || $people['count'] == 0)
{ //Nothing found, quit.
return AUTH_ERROR_NO_DN;
}

$dn = ($people[0]['dn']);

if (($dn!='')&&($password!=''))
{
$loginStatus = @ldap_bind($this->ldapconn, $dn, $password);
if ($loginStatus)
{
$fullname = $people[0]['fullname'][0];
if ($fullname=='')
{
$fullname =$dn;
}
$user = array(
'logged_in_dn' => $dn,
'password' => $password,
'username' => $fullname,
'cn' => $username,
'mail' => $people[0]['mail'][0],
'status' => 'AUTHENTICATED'
);
} else
{
$user = array(
'status'=> array('AUTH_ERROR_WRONG_PASSWORD'),
'details' => array(
'logged_in_dn' => '',
'password' => '',
'username' => '',
'cn' => '',
'mail' => '',
'status' => 'AUTHENTICATED'
)
);
}
} else
{
$user = array(
'status'=> array('AUTH_ERROR_NO_DN'),
'details' => array(
'logged_in_dn' => '',
'password' => '',
'username' => '',
'cn' => '',
'mail' => '',
'status' => 'AUTHENTICATED'
)
);
}
return $user;
}

这是执行方法的单元测试:类 unit_ldapConnectTest 扩展了 TadPhpUnitTestCase

{

function testLdapconnection () {
$ldap = new LDAP();
$user = $ldap->signin('myname','password','');


}
}

最佳答案

这可能是 LDAP 版本问题。

在你调用 ldap_connect 之后调用这个:

ldap_set_option($this->ldap_conn, LDAP_OPT_PROTOCOL_VERSION, 3);

关于PHP 5.3.5 ldap_search() : Search: Can't contact LDAP server,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7720795/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com