dtvgo28624
dtvgo28624
2013-05-20 09:42
浏览 71
已采纳

使用URL的PHP​​ LDAP连接

I have a problem while trying to connect from an Ubuntu server with PHP5 to a LDAP server using URL('ldap://hostname/'). The code works fine when I'm not using the URL format ($server = 'hostname').

The code:

$server = 'ldap://hostname/';

$ldapconn = ldap_connect($server, 3268) or die("Could not connect to LDAP server.");

if ($ldapconn) {
    $ldapbind = @ldap_bind($ldapconn, 'username', 'password');
    $error_ldap_code =  ldap_errno($ldapconn) ;
    if($error_ldap_code==0) {
        echo 'Connected!!!';
    }
}

Edit:

I needed ldaps, but I saw that with ldap I have the same problem. While the problem related to ldap was solved by adding the port in the URL, I still had the ldaps issue. Anyway, I managed to bypass it by using ldap_start_tls ( resource $link ) after connecting using only the hostname (without URL format).

图片转代码服务由CSDN问答提供 功能建议

尝试使用URL从Ubuntu服务器连接到LDAP服务器时遇到问题('ldap: //hostname/').nn当我不使用URL格式( $ server ='hostname')时,代码工作正常。

代码 :

  $ server ='ldap:// hostname /'; 
 
 $ ldapconn = ldap_connect($ server,3268)或die(“无法连接到LDAP 服务器。“); 
 
if($ ldapconn){
 $ ldapbind = @ldap_bind($ ldapconn,'username','password'); 
 $ error_ldap_code = ldap_errno($ ldapconn); 
 if($  error_ldap_code == 0){
 echo'Connected !!!'; 
} 
} 
   
 
 

编辑: < 我需要 ldaps ,但是我看到 ldap 我遇到了同样的问题。 虽然通过在URL中添加端口解决了与ldap相关的问题,但我仍然遇到了ldaps问题。 无论如何,在仅使用主机名(没有URL格式)连接后,我设法绕过它使用 ldap_start_tls(resource $ link)

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • dongye1912
    dongye1912 2013-05-20 09:55
    已采纳

    Try specifying the port in the URL - it's not the standard port 389. So 'ldap://hostname:3268'?

    点赞 评论
  • dpfwhb7470
    dpfwhb7470 2013-05-20 09:58

    Unless you are using LDAP with SSL , you are not required to specify ldap:// in 1st parameter of ldap_connect() function.

    Therefore, ldap_connect('hostname') is correct.

    Note: For LDAP with SSL , you can use ldap_connect('ldaps://hostname') .

    Reference: http://php.net/manual/en/function.ldap-connect.php

    点赞 评论

相关推荐