5 Replies - 2197 Views - Last Post: 18 August 2015 - 04:59 AM

#1 munanshu   User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 43
  • Joined: 27-October 14

How do we connect and bind openldap user using wamp server

Posted 17 August 2015 - 04:15 AM

I've installed openldap setup for windows and using these details of ldap user


ip address : http://localhost/
full distinguished name :cn=name,cn=users,dc=mydomain,dc=com,
server name: ldap://server1
pasword : secret
domain : mydomain.com

now i am trying to get username=name given in the code below to be authenticated from ldap server . It is connecting but data bind and search are generating these errors.

Warning: ldap_bind(): Unable to bind to server: Can't contact LDAP server in C:\wamp\www\ldap authentication\connect.php on line 14


Warning: ldap_search(): supplied argument is not a valid ldap link resource in C:\wamp\www\ldap authentication\connect.php on line 15

I am new at ldap never used before . could anyone tell me where am i wrong or missing something. I am using this code given below.
<?php
$domain = 'mydomain.com';
$username = 'name';
$password = 'secret';
$ldapconfig['host'] = 'ldap://server1';
$ldapconfig['port'] = 389;
$ldapconfig['basedn'] = 'dc=mydomain,dc=com';

$ds=ldap_connect($ldapconfig['host'], $ldapconfig['port']);
ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
ldap_set_option($ds, LDAP_OPT_REFERRALS, 0);

$dn="cn=users,".$ldapconfig['basedn'];
$bind=ldap_bind($ds, $username .'@' .$domain, $password);
$isITuser = ldap_search($bind,$dn,'(&(objectClass=users)(sAMAccountName=' . $username. '))');
if ($isITuser) {
echo("Login correct");
} else {
echo("Login incorrect");
}
?>


Is This A Good Question/Topic? 0
  • +

Replies To: How do we connect and bind openldap user using wamp server

#2 CTphpnwb   User is offline

  • D.I.C Lover
  • member icon

Reputation: 3825
  • View blog
  • Posts: 13,935
  • Joined: 08-August 08

Re: How do we connect and bind openldap user using wamp server

Posted 17 August 2015 - 09:28 AM

http://php.net/manua...dap-connect.php

ldap != ldaps
Was This Post Helpful? 0
  • +
  • -

#3 munanshu   User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 43
  • Joined: 27-October 14

Re: How do we connect and bind openldap user using wamp server

Posted 17 August 2015 - 09:59 PM

ok but result is still same .

i've changed "ldap://server1"to"ldaps://ldap.mydomain.com". and connectivity is not an issue . Binding of data is the issue i.e. ldap_bind($ds, $username .'@' .$domain, $password);. why is that not working
Was This Post Helpful? 0
  • +
  • -

#4 munanshu   User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 43
  • Joined: 27-October 14

Re: How do we connect and bind openldap user using wamp server

Posted 17 August 2015 - 10:36 PM

Again same error with this code :

<?php
    // using ldap bind
    $ldaprdn  = 'cn=name,cn=users,dc=mydomain,dc=com';     // ldap rdn or dn
    $ldappass = 'secret';  // associated password

    // connect to ldap server
    $ldapconn = ldap_connect("ldap://server1")
            or die("Could not connect to LDAP server.");

    // Set some ldap options for talking to 
    ldap_set_option($ldapconn, LDAP_OPT_PROTOCOL_VERSION, 3);
    ldap_set_option($ldapconn, LDAP_OPT_REFERRALS, 0);

    if ($ldapconn) {

            // binding to ldap server
            $ldapbind = ldap_bind($ldapconn, $ldaprdn, $ldappass);

            // verify binding
            if ($ldapbind) {
                echo "LDAP bind successful...\n";
            } else {
                echo "LDAP bind failed...\n";
            }

    }

?>


in the link given by you @ctphpnwb

This post has been edited by munanshu: 17 August 2015 - 10:40 PM

Was This Post Helpful? 0
  • +
  • -

#5 JackOfAllTrades   User is offline

  • Saucy!
  • member icon

Reputation: 6258
  • View blog
  • Posts: 24,026
  • Joined: 23-August 08

Re: How do we connect and bind openldap user using wamp server

Posted 18 August 2015 - 04:18 AM

For troubleshooting LDAP issues in code, a separate LDAP browser, like the one found here, is invaluable for debugging.
Was This Post Helpful? 0
  • +
  • -

#6 no2pencil   User is offline

  • Professor Snuggly Pants
  • member icon

Reputation: 6821
  • View blog
  • Posts: 31,442
  • Joined: 10-May 07

Re: How do we connect and bind openldap user using wamp server

Posted 18 August 2015 - 04:59 AM

If the credentials that you are passing are correct, then I'm not sure this is a php related error. Code is code, & it does what it does. A service not correctly running or binding however, that is a server issue.

Moving to Web Servers & Hosting.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1