I am trying to connect to a secure LDAP server (using LDAPs) via PHP, but I am having problems with it. I get the following error
Warning: ldap_bind()
I think you just need to set the ldap protocol version to be 3
echo "LDAP query test
";
echo "Connecting ...";
$ldap_server = 'ldaps://server';
$ldap_port = '636';
$ds = ldap_connect($ldap_server, $ldap_port);
if ($ds)
{
//add this
if (!ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3))
{
fatal_error("Failed to set LDAP Protocol version to 3, TLS not supported.");
}
echo "
Binding ...";
$r=ldap_bind($ds); // this is an "anonymous" bind, typically
// read-only access
echo "Bind result is " . $r . "
";
echo "Searching for (sn=S*) ...";
// Search surname entry
$sr=ldap_search($ds, "ou=people,o=server.ca,o=server", "uid=username*");
echo "Search result is " . $sr . "
";
echo "Number of entires returned is " . ldap_count_entries($ds, $sr) . "
";
echo "Getting entries ...";
$info = ldap_get_entries($ds, $sr);
echo "Data for " . $info["count"] . " items returned:
";
print_r($info);
// for ($i=0; $i<$info["count"]; $i++) {
// echo "dn is: " . $info[$i]["dn"] . "
";
// echo "first cn entry is: " . $info[$i]["cn"][0] . "
";
// echo "first email entry is: " . $info[$i]["mail"][0] . "
";
// }
echo "Closing connection";
ldap_close($ds);
}
else
{
echo "Unable to connect to LDAP server
";
}