Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialAvaronnan Abhinesh
193 PointsLDAP Authentication using PHP
when I use normal procedure, I get the ldap_connect('hostname') connected to any hostname. Even when I give the wrong server name and wrong port number. why is that so. Also the ldap_bind() always fails.
Code Sample:
$username = 'username';
$password = 'password';
$ldapconfig['host'] = "hostname";
$ldapconfig['port'] = NORMAL/SSL Port; // which one to use?
$ldapconfig['basedn'] = ',dc=XXX,dc=YYY,dc=com';
$ds=ldap_connect($ldapconfig['host'], $ldapconfig['port']);
if(!ds) {
echo "Unable to connect to:";
echo $ldapconfig['host'];
}else{
echo "Connected";//Always shows connected :(
}
ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
ldap_set_option($ds, LDAP_OPT_REFERRALS, 0);
$dn=$ldapconfig['basedn'];
$bind=ldap_bind($ds, 'cn='. $username . $ldapconfig['basedn'], $password);
if (!$bind) {
// Nope! Always fail
echo "\r\nBinding FAILED\r\n";
echo "\r \n " + ldap_errno($ds);
echo "\r \n " + ldap_error($ds);
}else{
echo "\r\nBinding works\r\n";
}