<?php
error_reporting(E_ALL);
$_ldap_dn = "ou=OUHochschulnetzwerk,dc=hsnet,dc=hs-ludwigsburg,dc=de";
$ds=@ldap_connect("141.10.128.30", "389");
ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);

$uid=$_GET["uid"];
$_ad_username="LDAPqueryUser";
$_ad_password="ldHS332";

if ($ds) {
$r=ldap_bind($ds, $_ad_username, $_ad_password);

  // Suchen &uuml;ber uid
  $sr=ldap_search($ds, $_ldap_dn, "samaccountname=$uid");
  $info = ldap_get_entries($ds, $sr);
  $anzahl = ldap_count_entries($ds,$sr);

$uid          = $info[0]['samaccountname'][0];
$vorname      = $info[0]['givenname'][0];
$nachname     = $info[0]['sn'][0];
$dn           = $info[0]['dn'];
$ers          = array('Ä' => 'Ae','Ö' => 'Oe','Ü' => 'Ue','ä' => 'ae','ö' => 'oe','ü' => 'ue','ß' => 'ss');
$dn           = strtr($dn,$ers); 
$mail         = $info[0]['mail'][0];
$mtknr        = $info[0]['description'][0];
$ag           = substr(ldap_explode_dn($dn,1)[1],0,-3);
$jahrgang     = substr(ldap_explode_dn($dn,1)[1],-2,2);
$stgText      = substr(ldap_explode_dn($dn,1)[2],0,-2);
$stg          = substr(ldap_explode_dn($dn,1)[2],0,1);

echo"
<table>
<tr>
  <td width=120>
   uid:
  </td>
  <td>
   $uid
  </td>
</tr>
<tr>
  <td>
   vorname:
  </td>
  <td>
   $vorname
  </td>
</tr>
<tr>
  <td>
   nachname:
  </td>
  <td>
   $nachname
  </td>
</tr>
<tr>
  <td>
   mail:
  </td>
  <td>
   $mail
  </td>
</tr>
<tr>
  <td>
   mtknr:
  </td>
  <td>
   $mtknr
  </td>
</tr>
<tr>
  <td>
   ag:
  </td>
  <td>
   $ag
  </td>
</tr>
<tr>
  <td>
   jahrgang:
  </td>
  <td>
   $jahrgang
  </td>
</tr>
<tr>
  <td>
   StgText:
  </td>
  <td>
   $stgText
  </td>
</tr>
<tr>
  <td>
   stg:
  </td>
  <td>
   $stg
  </td>
</tr>

</table>
";
  ldap_close($ds); 
} else {
  echo "<h4>Verbindung zum LDAP Server nicht m&ouml;glich</h4>"; 
} // Ende if
?>