PHP/LDAP simple function doesn't work

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
potato_chip
Forum Newbie
Posts: 20
Joined: Mon Oct 06, 2008 10:38 am

PHP/LDAP simple function doesn't work

Post 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.
Last edited by pickle on Wed Oct 08, 2008 5:59 pm, edited 1 time in total.
Reason: Re-numbering real-world IP
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: PHP/LDAP simple function doesn't work

Post 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.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
potato_chip
Forum Newbie
Posts: 20
Joined: Mon Oct 06, 2008 10:38 am

Re: PHP/LDAP simple function doesn't work

Post 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...
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: PHP/LDAP simple function doesn't work

Post by pickle »

Sounds like the server software isn't running.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
potato_chip
Forum Newbie
Posts: 20
Joined: Mon Oct 06, 2008 10:38 am

Re: PHP/LDAP simple function doesn't work

Post 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!!!
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: PHP/LDAP simple function doesn't work

Post by pickle »

That'd be a guess.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Post Reply