Search users in AD using the adldap class in php

Asked

Viewed 380 times

1

You can list AD users using the adldap.. class in php

    try
    {
        $adldap = new adLDAP();
    }
    catch (adLDAPException $e)
    {
        echo $e;
        exit();
    }
    $username = $_POST['nome'];
    $password = $_POST['senha'];
    //authenticate the user
    if ($adldap - > authenticate($username, $password))
    {
        //establish your session and redirect
        session_start();
        $_SESSION["username"] = $username;
        $_SESSION["userinfo"] = $adldap - > user() - > info($username);

        print 'conectando';
        print 'feito';

        foreach($_SESSION["userinfo"] as $te)
        {
            //print_r($te);
        }

        $result = $adldap - > user() - > infoCollection($username, array("*"));
        echo $result - > displayName; //nesta linha ele mostra o nome do usuario
        echo $result - > mail; //aqui mostra o email
    }
    else
    {
        print "erro";
    }
 ?>

<form method="POST" action="valida.php" >
     <label>Usuario</label><input type="text" name="nome"/> 
     <label>Senha</label><input type="text" name="senha"/> 
     <input type="submit" value="Conectar"/>
 </form>

  • 2

    If you can explain better the problem you have in particular and, if possible, show code you have done where this problem is. Your question is too broad, see Help Center How to Ask.

1 answer

1

See if it works

<?php

$adldap = new adLDAP();

$data = new DateTime();

try
    {
        $adldap->authenticate("$usuario", "$senha");
    }

catch(adLDAPException $e)
{
echo $e;
exit();
}


$result = $adldap->user()->all();


for ($i = 1; $i < count($result); $i++):
    $username = $result[$i];
    $user = $adldap->user()->infoCollection("$username", array(
        "*"
    ));

    $data->setTimestamp($user->accountexpires);
    echo $user->displayName;
    echo $user->samaccountname;
    echo date_format($data, "d/m/Y");

?>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.