function authAD($username, $password, $Domain, $ldap_server) {
if ($password == ""){ // POZOR: pouziti prazdneho hesla by proslo
return(false);
}
if (function_exists('ldap_connect')) {
$auth_user = $username."@".$Domain;
if($connect = ldap_connect($ldap_server)){
ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
ldap_set_option($ds, LDAP_OPT_REFERRALS, 0);
//ldap_set_option(NULL, LDAP_OPT_DEBUG_LEVEL, 7); // pise do error logu apache prubeh
if(@ldap_bind($connect, $auth_user, $password)) {
ldap_close($connect);
return(true);
}
}
ldap_close($connect);
return(false);
}
else {
Die ("extension php_ldap neni dostupne");
}
}
if(authAD("username", "password", "DOMAIN", "ldap://ip_adress")) {
echo "login OK.";
// .... Vas kod
}
else {
echo "login ERROR";
// .... Vas kod
}
评论0