3
我有一个适用于我们公司所有其他PHP安装的LDAP PHP类。但是,现在我的代码已经从SuSE变成了Ubuntu 11.04。 PHP版本是5.3.5。PHP 5.3.5 ldap_search():搜索:无法联系LDAP服务器
我尝试连接到我们的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','');
}
}
你有SSL配置是否正确? –
您使用的是哪种目录服务器产品? –