1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
| class TEST_LDAP{
/* Paramètres de connexion LDAP */
private $user = 'admin';
private $password = 'xxxxxx';
private $host = 'SERVEUR';
private $domain = 'DOMAIN.service.entreprise.fr';
private $group = 'Postes_PC';
private $ds = '';
private $search = '';
private $dn = 'OU=Postes_PC,DC=DOMAIN,DC=service,DC=entreprise,DC=fr';
private $filter = "(&(&(sAMAccountType=805306369)(objectCategory=computer)(objectClass=computer)(cn=*)))";
private $info_ldap = "";
function test_search_ldap_pmf()
{
$this->ds = ldap_connect("ldap://{$this->host}.$this->domain}");
if($this->ds !== FALSE){ // là on vérifie si la connexion fonctionne
ldap_set_option($this->ds, LDAP_OPT_PROTOCOL_VERSION, 3);
ldap_set_option($this->ds, LDAP_OPT_REFERRALS, 0);
ldap_bind($this->ds, $this->user."@".$this->domain, $this->password);
$this->search = ldap_search($this->ds, $this->dn, $this->filter);
if($this->search !== FALSE)
$this->info_ldap = ldap_get_entries($this->ds, $this->search);
else echo 'search failed!';
ldap_unbind($this->ds);
//ldap_close($this->ds); inutile, c'est un alias de ldap_unbind
return true; // on rajoute un retour pour vérification
}
else echo 'connexion failed';
return false;
}
function getInfo(){
return $this->info_ldap;
}
} |
Partager