Search for users in AD using the adldap class in php

1

How to 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>
    
asked by anonymous 19.06.2014 / 14:43

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");

?>
    
04.07.2014 / 18:16