PHP:通过SSL连接到外部LDAP系统


PHP: Connecting to an external LDAP system over SSL

我需要将我的应用程序连接到外部LDAP系统。我已经设法将我的应用程序连接到本地OpenLDAP。但是当我尝试通过SSL连接外部时,我会遇到一些麻烦。

我的代码

 public static function ldapConnection($server, $port, $version, $auth_user, 
                     $auth_pass, $base_dn, $search_filter, $attributes=null)
 {
   if(!extension_loaded('ldap'))
   {
     echo "This php version does not seem comptible with LDAP. Please install the 
           php5-ldap module";
     Yii::app()->end();
   }
   if (!($connect = @ldap_connect("ldaps://ldap.unil.ch", 636)))
   {
     echo "Unable to connect to server ".$server."";
     Yii::app()->end();
   }
   if ($version == 3)
   {
     @ldap_set_option($connect, LDAP_OPT_PROTOCOL_VERSION, 3);
   }
   if (!(@ldap_bind($connect, $auth_user, $auth_pass)))
   {
     return false;
   }
   ...
   ...
 }

我的问题:

"ldap_bind"函数总是返回false

我确信用户名、密码和LDAP地址信息(我在LDAP客户端GUI中尝试过它们)。apache"ssl_module"已激活。

我知道我必须用LDAP服务器证书来管理一些东西。我花了一些时间在谷歌上,但我仍然被这个问题困扰着。

那么,有人能告诉我如何成功连接吗?。

我遇到了同样的问题,对我来说,解决方案是向服务器添加一个端口

$ad = @ldap_connect("ldaps://serverName:636", 636);