I am trying to use LDAP authentication using PHP.
Below is my code:
<?php
$ldaphost = 'ldap://ldapServer';
$ldapport = 389;
$ds = ldap_connect($ldaphost, $ldapport)
or die("Could not connect to $ldaphost");
ldap_set_option($ldapconn, LDAP_OPT_PROTOCOL_VERSION, 3);
ldap_set_option($ldapconn, LDAP_OPT_REFERRALS, 0);
//ldap_set_option($ds, LDAP_OPT_DEBUG_LEVEL, 7);
if ($ds)
{
$username = "testuser@domain.com";
$upasswd = "testpass";
$ldapbind = ldap_bind($ds, $username, $upasswd);
if ($ldapbind)
{print "Congratulations! $username is authenticated.";}
else
{print "Access Denied!";}
}
?>
But it raises the below error:
PHP Warning:
ldap_bind()
: Unable to bind to server: Can't contact LDAP server
Any idea as how can I get it resolved?
Note: Do we need ldap.config
file somewhere as I came across this term on some forum. I don't see any such file on my machine. I have php_ldap.dll
in ext folder and using Windows
.