简体   繁体   English

无法使用ldap_connect()将我的ohp应用程序连接到Openldap服务器,返回ressource id#2

[英]Unable to connect my ohp application to Openldap server with ldap_connect() , return ressource id#2

I'v installed Openldap in Ubuntu 14.04 and i'v also installed phpldapadmin everything looks fine until this step , but when i try to connect my php application with this script i have the same response as a result resource id #2 我已经在Ubuntu 14.04中安装了Openldap,并且还安装了phpldapadmin,直到这一步一切都很好,但是当我尝试使用此脚本连接php应用程序时,我得到的响应与结果资源ID#2相同

this is my script : 这是我的脚本:

$ds=ldap_connect("ladp://192.168.1.2",389)or die("Could not connect to $ldaphost");  

echo 'Le résultat de connexion est ' . $ds . '<br />';

if ($ds) { 
echo 'Liaison ...'; 
$username = "cn=admin,dc=ldap,dc=com";
$upasswd = "password";
$r=ldap_bind($ds,$username, $upasswd);    
echo 'Le résultat de connexion est ' . $r . '<br />';

If you are using LDAP 2 如果您使用的是LDAP 2

When OpenLDAP 2.xx is used, ldap_connect() will always return a resource as it does not actually connect but just initializes the connecting parameters. 使用OpenLDAP 2.xx时,ldap_connect()将始终返回资源,因为它实际上并不连接,而只是初始化连接参数。 The actual connect happens with the next calls to ldap_* funcs, usually with ldap_bind(). 实际连接发生在下一次对ldap_ *函数的调用时,通常是在ldap_bind()中。

I think you might need to test the result of the ldap_bind() like this suggestion in the manual 我认为您可能需要像手册中的建议那样测试ldap_bind()的结果

<?php

    $ds=ldap_connect("ldap://192.168.1.2",389)or die("Could not connect to $ldaphost");  

    $username = "cn=admin,dc=ldap,dc=com";
    $upasswd = "password";
    $r=ldap_bind($ds,$username, $upasswd);  
    // verify binding
    if ($r) {
        echo 'Le résultat de connexion est ' . $r . '<br />';
    } else {
        echo "LDAP bind failed...\n";
        echo ldap_error($ds);
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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