Consulta del Active Directory con la extensión Ldap:
<?php
$ldap_dn = 'xxx@miempresa.com';
$ldap_password = 'xxx';
$ldap_con = ldap_connect("x.miempresa.com",389) or die ("No ha sido posible conectarse al servidor");
if ($ldap_con){
ldap_set_option($ldap_con, LDAP_OPT_REFERRALS, 0);
ldap_set_option($ldap_con, LDAP_OPT_PROTOCOL_VERSION, 3);
$r=ldap_bind($ldap_con,$ldap_dn,$ldap_password) or die("Couldn't bind to AD!");
if ($r)
{
//$atributos=array('samaccountname', 'userprincipalname', 'displayname',"mail","memberof","department","displayname","telephonenumber","primarygroupid","objectsid");
$atributos = array('samaccountname');
$filtro='(&(objectClass=user)(objectCategory=person)(cn=*))';
$res=ldap_search($ldap_con,"dc=miempresa,dc=com",$filtro) ;
$num_entradas=ldap_count_entries($ldap_con, $res);
$entradas=ldap_get_entries($ldap_con, $res);
foreach($entradas as $i){
foreach($atributos as $j){ ?>
<?php $array=array($i[$j][0]);
}
}
}
}
ldap_close($ldap_con);
?>
<th>
<?php echo $form->labelEx($model,'usuariosolicitante'); ?>
<select name="usuariosolicitante" id="usuariosolicitante">
<option selected="selected">Usuario</option>
<?php
foreach($entradas as $i){
foreach($atributos as $j) {
$array=array($i[$j][0]);?>
<option value="<?= $i[$j][0] ?>"><?= $i[$j][0] ?></option>
<?php
</th>
}
}?>