刚刚学习了OpenLDAP,我希望与PHP集成。我做的是安装OpenLDAP这是我的结构:
然后,我想在PHP中集成这个LDAP,但我不知道如何获取此配置的信息(尝试使用此操作没有运气):
protected $baseDn = "dc=maxcrc,dc=com";
protected $dn = "cn=Manager,ou=group,o=accounts,dc=maxcrc,dc=com";
protected $groupOU = "ou=group";
protected $peopleOU = "ou=People";
protected $peopleOU = "ou=People";
这方面的专业知识可以帮助我吗?这是我的ldapconnection的完整代码
<?php
include_once('settings.php');
class LDAP_Connector {
protected $baseDn = "dc=maxcrc,dc=com";
// Distinguished name for the admin.
protected $dn = "cn=Manager,ou=group,o=accounts,dc=maxcrc,dc=com";
// The ou of groups.
protected $groupOU = "ou=group";
// The ou of people.
protected $peopleOU = "ou=People";
protected $ldapconn;
public function __construct() {
global $ldapHost, $ldapPort, $ldapUser, $ldapPassword;
message("Creating LDAP connector");
$this->ldapconn = ldap_connect($ldapHost, $ldapPort);
if ($this->ldapconn) {
message("LDAP Connected - ".$this->ldapconn);
}
else {
message("LDAP failed to connect");
}
}
public function authenticate($username, $password) {
$r = false;
global $ldapHost, $ldapPort, $ldapUser, $ldapPassword;
if ($this->ldapconn) {
$bind = ldap_bind($this->ldapconn, $this->dn, $ldapPassword);
if ($bind) {
//$uid = $ldapUser;
$uid = $username;
// Filter on the uid.
$filter = "(mail=". $uid . ")";
// Return the userPassword.
$attr = array("userpassword","rpDisabledState");
// Get the record for the user.
$result = ldap_search($this->ldapconn, $this->peopleOU . "," . $this->baseDn, $filter, $attr);
//message( "result = ".print_r($result, true) );
$entries = ldap_get_entries($this->ldapconn, $result);
//message( print_r($entries, true));
$ldapEncodedPW = "{SHA}".base64_encode(pack("H*", $password));
$userDisabled = $entries[0]["rpdisabledstate"][0];
message("User ".$username." state is ".$userDisabled);
if ($userDisabled) {
message("username ".$username." is disabled ");
}
if ($entries[0]["userpassword"][0]==$ldapEncodedPW && !$userDisabled) {
$r = true;
}
else {
message("Passwords do not match or the account has been disabled.");
message("Password (provided) = ".$ldapEncodedPW);
message("Password (ldap) = ".$entries[0]["userpassword"][0]);
}
}
}
return $r;
}
}
?>
希望有人可以帮我这个,我为这个stuf堆了一个星期:((
此致 Ť