PHP 8.5.0 Released!

Voting

: max(three, five)?
(Example: nine)

The Note You're Voting On

Josh A.
18 years ago
The OpenLDAP libraries will return error 53 (Server unwilling to perform) when trying to re-bind to a non-anonymous account if you accidentally leave the password field blank. If you want to authenticate against a different field than the dn, you have to bind to the server twice. Your code may look like the following:
<?
function ldapLogin($uname, $pass, $base_dn, $fname, $server, $port){
 $ldc=@ldap_connect($server, $port);
 if (!$ldc) return ERROR_CODE;
 
 $bn='cn=anonymous-user,'.$base_dn;
 $pw='anonymous-pass';
 $lbind=@ldap_bind($ldc, $bn, $pw);
 if (!$lbind) return ERROR_CODE;
 
 
 $ureturn=@ldap_search($ldc, $base_dn, "($fname=$uname)", array('dn', 'givenName', 'sn', 'mail'));
 
 
 $uent=@ldap_first_entry($ldc, $ureturn);
 if (!$uent) return ERROR_CODE;
 
 $bn=@ldap_get_dn($ldc, $uent);
 
 //This line should use $pass rather than $password
 $lbind=@ldap_bind($ldc, $bn, $password);
 // Now you can find the error
 echo ldap_error($ltc);
 if ($lbind) return true; else return false;
?>
Hope this helps someone else running in to the same error.

<< Back to user notes page

AltStyle によって変換されたページ (->オリジナル) /