0

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

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 />';
S.Amine
  • 13
  • 10
  • Is it as simple as `ladp:` =/= `ldap:` , Minor typo – RiggsFolly Apr 14 '16 at 10:48
  • What were you expecting? ldap_bind() is equivalent to mysql[i]_connect() in that it establishes a connection to a service (but requires the resource created by ldap_connect() as an argument - ldap_connect() doesn't actually connect). If its returning a resource id, then its successful. You still need to send a query to get some data back. – symcbean Apr 14 '16 at 10:50
  • yes i know that it doesn not actually connect but the variable $ds return always resource id#2 even if i enter an invalide host – S.Amine Apr 14 '16 at 11:00
  • @RiggsFolly i'v changed it to ldap but still the same response – S.Amine Apr 14 '16 at 11:01
  • @RiggsFolly when i execute the code it shows me 'Liaison...' but when it comes to ldap_bind it doesn't work – S.Amine Apr 14 '16 at 11:11
  • See my answer, refresh page first, I just finished editing it. echo out the error, that may help you fix whatever is wrong – RiggsFolly Apr 14 '16 at 11:15

1 Answers1

0

If you are using LDAP 2

When OpenLDAP 2.x.x is used, ldap_connect() will always return a resource as it does not actually connect but just initializes the connecting parameters. The actual connect happens with the next calls to ldap_* funcs, usually with ldap_bind().

I think you might need to test the result of the ldap_bind() like this suggestion in the manual

<?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);
    }
RiggsFolly
  • 93,638
  • 21
  • 103
  • 149