警告:ldap_start_tls(( [function.ldap-start-tls]:无法启动 TLS:服务器在第 13 行的/var/www/html/testldap/index.php 中不可用 Ldap_start_tls失败
我的配置如下
Centos 5.7 PHP 版本 5.3.3
PHP 53-LDAP 已配置。无论我尝试做什么,starttls问题都让我头疼。任何帮助将不胜感激。
好吧,我经历了一段多么有趣的旅程。
您遇到的问题是您的计算机不接受服务器的有效证书。解决此问题的简单方法是禁用检查,该检查在 ldap.conf 文件中或使用环境变量完成。
您可以在/etc/openldap/ldap.conf
(在Windows上c:'openldap'sysconf'ldap.conf
(编辑该文件,或者创建一个(如果尚不存在(并在其中放置以下行:
TLS_REQCERT never
。或者,您可以创建一个名为 LDAPTLS_REQCERT
的环境变量,其值为 never
。
一旦我完成了其中任何一件事,以下脚本对我有用:
<?php
// Settings
$host = 'server.domain.local';
$port = 389;
$user = 'administrator';
$pass = 'password';
// Connect, set options and bind
$ds = ldap_connect($host, $port);
if (!ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3)) exit('Could not disable referrals');
if (!ldap_set_option($ds, LDAP_OPT_REFERRALS, 0)) exit('Could not disable referrals');
if (!ldap_start_tls($ds)) exit('Could not start TLS');
if (!ldap_bind($ds, $user, $pass)) exit('Bind operation failed');
// A quick list operation to make sure it worked
if (!$result = ldap_list($ds, 'dc=domain,dc=local', 'objectClass=*')) exit('List operation failed');
print_r(ldap_get_entries($ds, $result));
令人讨厌的是,putenv('LDAPTLS_REQCERT=never');
和$_ENV['LDAPTLS_REQCERT'] = 'never';
都不起作用 - 您必须创建配置文件或静态设置变量。
如果要验证证书,则需要进一步阅读有关如何正确配置 OpenLDAP 的信息。
来源:
- http://marc.info/?l=php-windows&m=116127873321748&w=2
- http://www.php.net/manual/en/function.ldap-start-tls.php
- http://linux.die.net/man/5/ldap.conf
你安装了 PHP --with-ldap[=DIR]吗?
也:
- 如果您已经通过SSL连接到LDAP服务器,请不要使用ldap_start_tls((,例如"ldaps://hostame"。
- 使用 ldap://而不是 ldaps://调用 ldap_connect(( 以使 ldap_start_tls(( 成功
源。