Php ldap#u bind():无法绑定到服务器:Can';不要联系LDAP服务器

Php ldap#u bind():无法绑定到服务器:Can';不要联系LDAP服务器,php,ldap,Php,Ldap,我可以使用管理员用户名和密码进行远程访问,我在脚本中使用相同的用户名和密码。但是我得到了以下错误 警告:ldap_bind():无法绑定到服务器:无法在中联系ldap服务器 无法绑定到服务器。检查用户名/密码。 服务器响应: 错误号:-1 描述:无法联系LDAP服务器 <?php ini_set('display_errors',1); ini_set('display_startup_errors',1); error_reporting(-1); /

我可以使用管理员用户名和密码进行远程访问,我在脚本中使用相同的用户名和密码。但是我得到了以下错误

警告:ldap_bind():无法绑定到服务器:无法在中联系ldap服务器

无法绑定到服务器。检查用户名/密码。 服务器响应: 错误号:-1 描述:无法联系LDAP服务器

<?php
    ini_set('display_errors',1);
    ini_set('display_startup_errors',1);
    error_reporting(-1);

     // Username used to connect to the server
     $username = "Administrator";

     // Password of the user.
     $password = "password";

     // Either an IP or a domain.
     $ldap_server = "10.10.10.10";

     // Get a connection
     $ldap_conn = ldap_connect($ldap_server);

     // Set LDAP_OPT_PROTOCOL_VERSION to 3
     ldap_set_option($ldap_conn, LDAP_OPT_PROTOCOL_VERSION, 3) or die ("Could not set LDAP Protocol version");

     // Authenticate the user and link the resource_id with
     // the authentication.
     if($ldapbind = ldap_bind($ldap_conn, $username, $password) == true)
     {
     // Setup the data that will be used to create the user
     // This is in the form of a multi-dimensional
     // array that will be passed to AD to insert.
     $adduserAD["cn"] = "testuser";
     $adduserAD["sn"] = "User";
     $adduserAD["samaccountname"] = "testuser";
     $adduserAD["objectClass"] = "user";
     $adduserAD["displayname"] = "Test User";
     $adduserAD["userPassword"] = "Welcome123!";
     $adduserAD["userAccountControl"] = 544;

     $base_dn = "cn=testuser,cn=Users,DC=testdomain,DC=com";

     // Display some "waiting" text.
     echo "Trying to add the user to the system ...<br>";

     // Attempt to add the user with ldap_add()
     if(ldap_add($ldap_conn, $base_dn, $adduserAD) == true)
     {

     // The user is added and should be ready to be logged
     // in to the domain.
     echo "User added!<br>";
     }else{

     // This error message will be displayed if the user
     // was not able to be added to the AD structure.
     echo "Sorry, the user was not added.<br>Error Number: ";
     echo ldap_errno($ldap_conn) . "<br />Error Description: ";
     echo ldap_error($ldap_conn) . "<br />";
     }
     }else{
     echo "Could not bind to the server. Check the username/password.<br />";
     echo "Server Response:"

     // Error number.
     . "<br />Error Number: " . ldap_errno($ldap_conn)

     // Error description.
     . "<br />Description: " . ldap_error($ldap_conn);
     }

     // Always make sure you close the server after
     // your script is finished.
     ldap_close($ldap_conn);
    ?> 

您应该检查第一次
ldap\u connect(…)
调用的结果

以及:


尝试验证所有连接信息。这对我非常有帮助,可以确保您拥有正确的帐户信息和LDAP目录信息。

为什么下面的行中没有端口

$ldap_server = "10.10.10.10";
$ldap_conn = ldap_connect($ldap_server);
试试下面的方法

 if($authMethod == 0){
    $ldap_server = 'ldap://'.$host.':'.$port;
}else if($authMethod == 1) {
    $ldap_server = 'ldaps://'.$host.':'.$port;
}
$ldap_conn = ldap_connect($ldap_server);
然后检查$ldap_conn是否为真或假或任何其他返回代码。 端口#389是简单LDAP的默认端口,636是LDAP的默认端口。
我希望这能奏效:)。干杯

你能ping服务器吗?您是否尝试过LDAP浏览器来验证在PHP之外的连接?到目前为止你做了什么?我可以ping服务器,连接并运行其他php脚本。我已经确保在IIS 7.5上的php管理器中启用了ldap。您可以在命令行上运行基本的ldapsearch吗?输出是什么?您可以ping服务器,但可以在目标端口上远程登录吗?哪个港口?顺便说一下,您正在使用
ldap\u connect($ldap\u server)未指定$port,因此连接默认使用端口389上的ldap://协议。您的服务器可能需要ldaps://协议(通常在端口636上),甚至在端口389上通过ldap://启动ttls(-cmd行上的Z选项),无论如何,如果您需要SSL/TLS,请检查您的客户端计算机上是否有CA证书的副本。