2011-12-12 49 views
2

警告:ldap_start_tls()[function.ldap啓動-TLS]:無法啓動TLS:服務器是在第13個 Ldap_start_tls /var/www/html/testldap/index.php不可用失敗警告:ldap_start_tls()[function.ldap啓動-TLS]:無法啓動TLS:服務器不可用

我的配置是如下

Centos的5.7 PHP版本5.3.3

php53-LDAP已配置。無論我嘗試做什麼,最初的問題都讓我頭痛。任何幫助將不勝感激。

+0

請出示你的代碼,並建議您嘗試連接到什麼LDAP提供商。 – DaveRandom

回答

0

您是否installed PHP --with-ldap [= DIR]?

另外:

  1. 不要使用ldap_start_tls()如果你已經通過SSL連接例如到LDAP服務器「LDAPS:// hostame」。
  2. 調用ldap_connect()與LDAP://而非LDAPS://爲ldap_start_tls()接替

Source

+0

我已經配置php與php-ldap 我有我的系統管理員的活動目錄的設置,因此將需要使用它們。 –

2

嗯,這是一次有趣的旅程。

您遇到的問題是您的機器不接受服務器的證書有效。簡單的解決方法是禁用在ldap.conf文件中完成的檢查,或者使用環境變量。

您可以編輯在/etc/openldap/ldap.confc:\openldap\sysconf\ldap.conf在Windows上)的文件或創建一個,如果它不存在,並把這一行是:

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。

來源是:

+0

拯救生命。 'mkdir C:\ openldap \ sysconf'。 –