| Current Path : /var/www/html/mmishra/irp/mcell/ |
| Current File : /var/www/html/mmishra/irp/mcell/ldap.php |
<?php
// basic sequence with LDAP is connect, bind, search, interpret search
// result, close connection
echo "<h3>LDAP query test</h3>";
echo "Connecting ...";
$ds=ldap_connect("ldap.iiita.ac.in"); // must be a valid LDAP server!
echo "connect result is " . $ds . "<br />";
if ($ds) {
echo "Binding ...";
$r=ldap_bind($ds, "uid=mmishra,ou=users,dc=iiita,dc=ac,dc=in", "Mmishra");
// $r=ldap_bind($ds); // this is an "anonymous" bind, typically
// read-only access
echo "Bind result is " . $r . "<br />";
$sr=ldap_search($ds, "ou=users,dc=iiita,dc=ac,dc=in", "(&(uid=mmishra)(objectclass=posixAccount)(|(host=172.31.2.3)(host=\*)))");
if (($e = ldap_get_entries($ds, $sr)) && $e["count"] > 0) $r = 1;
echo "Searching for (sn=S*) ...";
echo "Search result is " . $sr . "<br />";
echo "Number of entries returned is " . ldap_count_entries($ds, $sr) . "<br />";
echo "Getting entries ...<p>";
$info = ldap_get_entries($ds, $sr);
echo "Data for " . $info["count"] . " items returned:<p>";
for ($i=0; $i<$info["count"]; $i++) {
$entry = ldap_first_entry($ds, $sr);
$attrs = ldap_get_attributes($ds, $entry);
for ($j=0;$j<$attrs["count"];$j++){
$att = $attrs[$j];
echo $att . " ---- ";
$atval = ldap_get_values($ds,$entry, $att);
for ($k=0;$k<$atval["count"];$k++){
echo $info[$i][$att][$k] . "<br />\n";
}
}
}
echo "Closing connection";
ldap_close($ds);
} else {
echo "<h4>Unable to connect to LDAP server</h4>";
}
?>