I have a nice little php script to query my LDAP/AD and perform a search. I now want to pass on the search variable of 'q' to a AJAX live search.
I'm almost there I just need to know what the query in the URL is.
For example when we use google the basic search query is google.com?=Yoursearchterm
so what is the URL actually sending for and LDAP/AD search?
This is my script
<p>
<form action="http://intranet/adquery/ajax/spotlight_v2/livesearch.php" method="post">
Search criteria:<br />
<input type="text" name="q" size="20"
maxlength="20" value="" /><br />
<input type="submit" value="Search" />
</form>
</p>
<?php
if( isset($_POST['q']) &&!empty($_POST['q']) ){
// all your ldap code
// Designate a few variables
$host = "10.10.10.10";
$user = "USER@DOMAIN";
$pswd = "PASSWORD";
$ad = ldap_connect($host)
or die( "Could not connect!" );
// Set version number
ldap_set_option($ad, LDAP_OPT_PROTOCOL_VERSION, 3)
or die ("Could not set ldap protocol");
// Binding to ldap server
$bd = ldap_bind($ad, $user, $pswd)
or die ("Could not bind");
// Create the DN
$dn = "OU=user,DC=DOMAIN,DC=com";
// Specify only those parameters we're interested in displaying
$attrs = array("displayname","mail","telephonenumber","givenname");
// Create the filter from the search parameters
$filter = "(|(givenName=".$_POST['q']."*) (sn=".$_POST['q']."*))";
$search = ldap_search($ad, $dn, $filter, $attrs)
or die ("");
$entries = ldap_get_entries($ad, $search);
if ($entries["count"] > 0) {
for ($i=0; $i<$entries["count"]; $i++) {
echo "<p>Name: ".$entries[$i]["displayname"][0]."<br />";
echo "Email: <a href=mailto:".$entries[$i]["mail"][0].">".$entries[$i]["mail"][0]."</a><br />";
echo "Phone: ".$entries[$i]["telephonenumber"][0]."</p>";
}
} else {
echo "<p>No results found!</p>";
}
ldap_unbind($ad);
}
?>
thanks all 😃