PHP Search LDAP server
Posted: Sat Sep 03, 2011 4:03 pm
I think this is the correct room for this question...
I've been trying to make a script for searcing my LDAP server.
I have success in connecting and listing the content, but something is wrong in my code for searching.
Here is my input html file:
And the search.php:

I've been trying to make a script for searcing my LDAP server.
I have success in connecting and listing the content, but something is wrong in my code for searching.
Here is my input html file:
Code: Select all
<html>
<head>
<title>Search</title>
</head>
<body>
<form action="search.php" method="POST">
<input type="text" name="name" length="30">
<input type="submit" name="submit" value = "Søk">
</form>
</body>
</html>Code: Select all
<?php
$ds=ldap_connect("ldap://10.10.160.4");
ldap_set_option($conn, LDAP_OPT_PROTOCOL_VERSION, 3);
if ($ds) {
$r=ldap_bind($ds);
$query = "(cn=" . $_POST['name'] . ")";
$sr=ldap_search($ds, "dc=dyndns,dc=org", "(cn=*)");
echo "Number of entries: " . ldap_count_entries($ds, $sr) . "<br />";
$info = ldap_get_entries($ds, $sr);
for ($i=0; $i<$info["count"]; $i++) {
echo "Navn: " . $info[$i]["cn"][0] . "<br />";
echo "Telefon: " . $info[$i]["telephoneNumber"][0] . "<br />";
echo "Mobil: " . $info[$i]["mobile"][0] . "<br />";
echo "E-post: " . $info[$i]["mail"][0] . "<br /><hr />";
}
echo "Closing connection";
ldap_close($ds);
} else {
echo "<h4>Unable to connect to LDAP server</h4>";
}
?>