Portál AbcLinuxu, 7. listopadu 2025 01:23
Řešení dotazu:
snad ti k necemu bude
$username = "test";
$password = "1234";
function authAD($username, $password, $Domain="domain.local", $ldap_server="ldap://192.168.x.x") {
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)) {
echo "login OK.";
// .... Vas kod
}
else {
echo "login ERROR";
// .... Vas kod
}
$ldap = ldap_connect("ldap.example.com");
if($ldap) {
ldap_set_option($ldap, LDAP_OPT_PROTOCOL_VERSION, 3);
$bindstatus = ldap_bind($ldap, "uid=".$username.", ou=Users, dc=example, dc=com", $password);
if($bindstatus) {
// přihlaš
} else {
// ošetři chybu
}
} else {
// ošetři
}
Trochu jsem to zjednodušil, takže předpokládám ošetřené vstupy. Jinde jsem použil jiný přístup, ale ten kód teď nemám dostupný.
) http://prirucka.ujc.cas.cz/?slovo=autentifikace
Tiskni
Sdílej:
ISSN 1214-1267, (c) 1999-2007 Stickfish s.r.o.