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 37 38 39 40 41 42 43 44
|
function recup_login($name)
{
// Connexion à l'Active Directory
$base_dn = "****,dc=fr";
$ad = ldap_connect("dc2000")
or die("Impossible de se connecter à l'AD!");
ldap_set_option($ad, LDAP_OPT_PROTOCOL_VERSION, 3);
ldap_set_option($ad, LDAP_OPT_REFERRALS, 0);
ldap_set_option($ad, LDAP_OPT_SIZELIMIT, 0);
$bd = ldap_bind($ad,"CN=SvcReaderADIntranet,OU=Intranet,OU=Applications,DC=****,DC=fr","****")
or die("Couldn't bind to AD!");
$filter = "(CN=$name)";
if($name!="")
{
$result = ldap_search($ad, $base_dn,$filter);
if ($result)
{
//$entries = ldap_get_entries($ad, $result);
$info = ldap_get_entries($ad, $result);
for ($i=0; $i<$info["count"]; $i++)
{
for ($ii=0; $ii<$info[$i]["count"]; $ii++)
{
if($info[$i][$ii]=='samaccountname')
{
$attrib = $info[$i][$ii];
return $info[$i][$attrib][0];
}
}
}
}
}
return false;
} |
Partager