[英]PHP LDAPS supplied argument is not a valid ldap link resource
I am trying to connect to a remote LDAP server from a local Ubuntu VM Box on my Windows machine. 我试图从我的Windows机器上的本地Ubuntu VM Box连接到远程LDAP服务器。 The PHP code is:
PHP代码是:
$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:
但是,当我之后运行此PHP代码时:
$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
警告:ldap_search():提供的参数不是第37行/usr/share/nginx/www/ldap_test.php中的有效ldap链接资源
(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_search命令的行。如果连接成功并且创建了链接资源,这没有意义 - 任何想法?
ldap_bind
will return true
or false
. ldap_bind
将返回true
或false
。 You need to pass the result of ldap_connect
to ldap_search
instead - which is $ldap
in your example. 您需要将
ldap_connect
的结果传递给ldap_search
- 在您的示例中为$ldap
。
$sr = ldap_search($ldap, "OU=User Accounts,DC=Domain1,DC=foobar,DC=Local", "(|(sn=*))");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.