PHP 8.5.0 Alpha 1 available for testing

Voting

: min(seven, seven)?
(Example: nine)

The Note You're Voting On

[nie ten]archie
15 years ago
I'm using OpenLDAP on linux and found out the right bind sequence the hard way... so I'm sharing it with you:

(wkaiser solution is ok if everything works fine, but for development I would suggest using ldap_error command like this)

<?php
$ldapconfig
['host'] = '10.10.10.10';
$ldapconfig['port'] = NULL;
$ldapconfig['basedn'] = 'dc=company,dc=com';

$ds=ldap_connect($ldapconfig['host'], $ldapconfig['port']);

$dn="uid=".$username.",ou=people,".$ldapconfig['basedn'];

if (
$bind=ldap_bind($ds, $dn, $password)) {
echo(
"Login correct");
} else {

echo(
"Unable to bind to server.</br>");

echo(
"msg:'".ldap_error($ds)."'</br>");#check if the message isn't: Can't contact LDAP server :)
#if it say something about a cn or user then you are trying with the wrong $dn pattern i found this by looking at OpenLDAP source code :)
#we can figure out the right pattern by searching the user tree
#remember to turn on the anonymous search on the ldap server
if ($bind=ldap_bind($ds)) {

$filter = "(cn=*)";

if (!(
$search=@ldap_search($ds, $ldapconfig['basedn'], $filter))) {
echo(
"Unable to search ldap server<br>");
echo(
"msg:'".ldap_error($ds)."'</br>");#check the message again
} else {
$number_returned = ldap_count_entries($ds,$search);
$info = ldap_get_entries($ds, $search);
echo
"The number of entries returned is ". $number_returned."<p>";
for (
$i=0; $i<$info["count"]; $i++) {

var_dump($info[$i]);#look for your user account in this pile of junk and apply the whole pattern where you build $dn to match exactly the ldap tree entry
}
}
} else {
echo(
"Unable to bind anonymously<br>");
echo(
"msg:".ldap_error($ds)."<br>");
}
}
?>

as you can see most of the examples use "cn=username" and OpenLDAP uses "uid=username" but who knows what will be used in the future builds, this code will help you check it out (I hope :)

<< Back to user notes page

To Top