Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ldap_bind function problem

Status
Not open for further replies.

awingnut

Programmer
Feb 24, 2003
759
US
I am having a problem authenticating users via the ldap_bind function. This may be more of an LDAP question then PHP but I am hoping someone here has sufficient experience with both to help me. Here is the troubling code:
Code:
$bind=ldap_bind($connect,"uid=".$username.",dc=mydomain,dc=com",$_POST['password']);
I don't know what kind off error I will get for an invalid password but I know the password in my testing is correct. I am guessing an invalid password will give me a different error but here is the one I get:

Warning: ldap_bind(): Unable to bind to server: Protocol error in /Library/WebServer/Documents/emailchpw.php on line 70

My 'ldap_connect' call returned successfully so the value of '$connect' is good. Can someone at least tell me what this error means? TIA.
 
Are you using openladp? What kind of php are you using? 4.2.3 uses version 2 mode and you might be using version 3 mode in your ldap. Try the ldap_set_option to see if it fixes the problem.
 
Thanks for the reply. I set the 'ldap_set_option' to version 3 but it did not help.
 
After more testing and research, I found a PHP application that is successfully doing an 'ldap_bind'. Although the application is quite complex, I could not find anything obvious that is doing, different from me. Perhaps if I posted more if my code, someone can see the problem. Thanks.
Code:
<?php
	if (isset($_POST['validate'])) {
		if (!strlen($_POST['userid'])>0) {
			echo '<font class=error>No email address entered.</font>';
		}
		elseif (!strlen($_POST['oldpw'])>0) {
			echo '<font class=error>Old password not entered.</font>';
		}
		elseif (!strlen($_POST['password'])>0) {
			echo '<font class=error>New password not entered.</font>';
		}
		else {
			if ($_POST['password']==$_POST['oldpw']) {
				echo '<font class=error>Passwords cannot be reused.</font>';
			}
			else {
				$connect=ldap_connect("myhost.mydomain.com");
				if (!$connect) {
					echo '<font class=error>Unable to connect to server, notify IT or try later.</font>';
				}
				else {
					$nma=explode('.',$_POST['userid']);
					$name=implode('',$nma);
					if (ldap_set_option($connect,LDAP_OPT_PROTOCOL_VERSION,3)) {
						$bind=ldap_bind($connect,'uid='.$name.',dc=mydomain,dc=com',$_POST['oldpw']);
.
.
.
?>
 
I've hit a brick wall with this problem. I cannot get this to work even though I have another PHP application that does. The implication is that there is something I am missing in setting up the connection. Doesn't someone out there have a chisel and hammer? TIA.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top