通过PHP连接到LDAP的问题

时间:2016-06-12 22:50:12

标签: php ldap

由于所有权更改,我的公司最近更改了域名,因此我遇到了在新域名上完成LDAP绑定的问题。

我的connect命令正确创建了资源,但是当我去绑定时,我得到了错误。

  

“警告:ldap_bind():无法绑定到服务器:需要强(呃)身份验证”

我没有使用ldaps。我已经确认我有正确的LDAP域名。

public class Meaning implements Serializable { @Id @Column(name = "id", updatable = false, nullable = false) @GeneratedValue(strategy = GenerationType.AUTO) private int id; @JsonIgnore @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "vocabulary_words_id", nullable = false, updatable = false) private VocabularyWord vocWord; @JsonIgnore @Column(name = "vocabulary_words_id", updatable = false, insertable = false) private int vocWordId; @Column(name = "w_type", nullable = true, unique = false) private String wType; @Column(name = "example", nullable = true, unique = false) private String example; @Column(name = "definition", nullable = true, unique = false) private String definition; @Column(name = "translation", nullable = true, unique = false) private String translation; //+ getters and setters } 是资源,$ad是添加了域名的用户名,$dmun是密码。

$pw

这是一个内联网网站。

1 个答案:

答案 0 :(得分:0)

尝试此代码。这段代码对我有用

$username = 'username';
$password = 'password';
$ldap_host = "domain.com";
$ldap_port = 389;
$base_dn = "DC=domain,DC=com";
$filter = '(sAMAccountName=' . $username . ')';
$connect = ldap_connect($ldap_host, $ldap_port) or exit("Error : Could not connect to LDAP server.");
if ($connect) {
    ldap_set_option($connect, LDAP_OPT_PROTOCOL_VERSION, 3);
    ldap_set_option($connect, LDAP_OPT_REFERRALS, 0);
    if (@$bind = ldap_bind($connect, "$username@domain.com", $password)) {
        echo "Bind Successfull";
    } else {
        echo "Invalid Username / Password";
    }
}