Page 1 of 1

PHP/LDAP simple function doesn't work

Posted: Wed Oct 08, 2008 4:56 pm
by potato_chip
~pickle | Please use [ code=html ], [ code=php ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: :arrow: Posting Code in the Forums to learn how to do it too.


I'm new to PHP/LDAP. And tried to use LDAP bind function:ldap_bind().

The weird thing is if I use anonymous bind, it shows:

LDAP bind successful...


However, if I give my credentials (my username and password), it always display warning message:
Warning: ldap_bind() [function.ldap-bind]: Unable to bind to server: Inv
alid credentials in C:\wamp\virtual\wga\itest2\www\ldapConnect\bindTest.php on line 13
LDAP bind failed...

Here is my very simple code:

Code: Select all

<?php
 
$host = 'ldaps://123.45.67.89'; //I provide the IP address of AD controller
 
// using ldap bind
$ldaprdn  = '';     // ldap rdn or dn
$ldappass = '';  // associated password
 
$ldapconn = ldap_connect($host)
    or die("Could not connect to LDAP server.");
 
if ($ldapconn) {
 
    // binding to ldap server
    $ldapbind = ldap_bind($ldapconn, $ldaprdn, $ldappass);
 
    // verify binding
    if ($ldapbind) 
    {
        echo "LDAP bind successful...<br />";    
    
} else {
        echo "LDAP bind failed...";
    }
}
 
// all done? clean up
ldap_close($ldapconn);
 
?>
Can somebody tell me what's wrong? I also noticed when I check my phpinfo(), PHP Version 5.2.5, it shows:
LDAP Support: enabled
RCS Version: $Id: ldap.c,v 1.161.2.3.2.11 2007/07/17 09:09:42 jani Exp $
Total Links: 0/unlimited
API Version: 2004
Vendor name: OpenLDAP
Vendor Version: 0

WHY the vendor version is 0? Is than an error? if it is, is it due to the wrong configuration? What's the fix? Does this error caused my LDAP function not working properlly?

Thanks, I'm really frustrated now. :banghead:


~pickle | Please use [ code=html ], [ code=php ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: :arrow: Posting Code in the Forums to learn how to do it too.

I also re-numbered your IP - assuming you don't want the world to contact that IP.

Re: PHP/LDAP simple function doesn't work

Posted: Wed Oct 08, 2008 6:02 pm
by pickle
I don't know about the version number, but it sounds possible that the credentials are invalid. On my LDAP box, the username isn't just joeUser it's cn=joeUser,o=NameOfMyOrganization - maybe that's causing the problem.

Anonymous binds can be allowed separate from an actual account bind, so anonymous binds might not require such a strict username syntax.

Re: PHP/LDAP simple function doesn't work

Posted: Wed Oct 08, 2008 6:23 pm
by potato_chip
Now, I even try the anoynmous binding. It aslo fails! What happened!

here is the error message:
Warning: ldap_bind() [function.ldap-bind]: Unable to bind to server: Can't contact LDAP server in C:\wamp\virtual\wga\itest2\www\ldapConnect\lasttest.php on line 15
LDAP bind failed...

Re: PHP/LDAP simple function doesn't work

Posted: Thu Oct 09, 2008 9:56 am
by pickle
Sounds like the server software isn't running.

Re: PHP/LDAP simple function doesn't work

Posted: Thu Oct 09, 2008 2:30 pm
by potato_chip
pickle wrote:Sounds like the server software isn't running.
Do you mean the AD server is not working or what? I need to give our IT department the clear instruction to fix the problem. Thanks for helping!!!

Re: PHP/LDAP simple function doesn't work

Posted: Thu Oct 09, 2008 2:48 pm
by pickle
That'd be a guess.