Connection between Active Directory and PHP, how to do?

Asked

Viewed 1,574 times

4

Good morning, I am doing a job for the school and asked me to do a kind of auto-fill using AD (Active Directory), I mean through ad could fill the field "Name" and know all the permissions of that user, but I do not know how to do it.

The part where I need help, is how do I link between AD and php, for example in php I have a field "Worker name" and how do I get the worker name from AD.

1 answer

2

The code below has not been tested!

To accomplish this task, you will need to observe the details embedded in the process

carried out under the LDAP protocol.

Enable the extension in the php.ini file

extension=php_ldap.dll

Uncomment the line above.

<?php

// sequência conecta, vincula , pesquisa ,trata a pesquisa , resultado e fecha conexão

// tipo mysql

echo "LDAP teste";

echo "Conectando ...";

$ds=ldap_connect("ldap.php.net"); // deve ser um servidor LDAP valido

echo "Resultado da conexão : " . $ds . "<br/>";

if ($ds) {

echo "Vinculando ...";

$r=ldap_bind($ds);

echo "Resultado: " . $r . "<br/>";

echo "Procurando por (campusid=000000137118)  ...";

$sr=ldap_search($ds, "ou=University of California Irvine,o=University of California, c=US", "campusid=000000137118");

echo "Resultado da pesquisa" . $sr . "<br/>";

echo "Número de entradas" . ldap_count_entries($ds, $sr) . "<br/>";

echo "Pega as entradas...<p>";

$info = ldap_get_entries($ds, $sr);
   echo "Dados " . $info["count"] . "retornados:<p>";

for ($i=0; $i<$info["count"]; $i++) {
   echo "dn: " . $info[$i]["dn"] . "<br/>";
   echo "Primeira cn: " . $info[$i]["cn"][0] . "<br/>";
   echo "Primeiro tipo: " . $info[$i]["type"][0] . "<br/><hr/>";
   }

 echo "Fecha a conexão";
   ldap_close($ds);

} else {
   echo "Pi,pi, pi, piiiiiiiiiiiiiiii";
}
?>

Then with the obtained data, assemble a function to take the data and display.

Any difficulty put in the comment, for us to adjust.

Resources and references:

code above / Microsoft LDAP / PHP LDAP

Browser other questions tagged

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