I am trying to connect to a remote LDAP server from a local Ubuntu VM Box on my Windows machine. The PHP code is:
$ldap = ldap_connect("ldaps://11.22.33.44",636);
ldap_set_option ($ldap, LDAP_OPT_REFERRALS, 0);
ldap_set_option($ldap, LDAP_OPT_PROTOCOL_VERSION, 3);
$username = "domain\usr";
$password = "blah";
$ds = ldap_bind($ldap, $username, $password );
if( $ds ){
echo "logged in!";
}
else{
echo "failed to log in!";
exit;
}
When running this I get the 'logged in!' message, so I'm assuming that the connection is working. However, when I run this PHP code afterwards:
$sr = ldap_search($ds, "OU=User Accounts,DC=Domain1,DC=foobar,DC=Local", "(|(sn=*))");
I get this error:
Warning: ldap_search(): supplied argument is not a valid ldap link resource in /usr/share/nginx/www/ldap_test.php on line 37
(which refers to the line that contians the ldap_search command. This doesn't make sense if the connection is successful and a link resource is created - any ideas?
ldap_connectinto the URI as the second parameter is not used when an LDAP-URI is passers as first parameter. So callingldap_connect("ldaps://11.22.33.44:636");would be the better way. - heiglandreas