开发者

Simple LDAP Search with PHP JQuery [closed]

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. Closed 9 years ago.

I want to do a simple ajax search of LDAP (or AD) using PHP and JQuery. I have read a number of tutorials that search mysql, such as:

http://www.codeforest.net/simple-search-with-php-jquery-and-mysql

I want to replace the mysql connection with my ldap connection details details below. Could someone help me out in getting this to work as I cant get the results to display.

Thanks

LDAP Connection script

    <?php echo "<?xml version='1.0' encoding='utf-8'  ?>" ?><?php echo "<ul class='LSRes'>" ?>
<?php
if( isset($_GET['q']) &&!empty($_GET['q']) ){
// all your ldap code

// Designate a few variables
$host = "10.10.10.10"; // Add in your AD host name or IP
$user = "DOMAIN\user"; // Add in your AD access account user name
$pswd = "password"; // Add in your AD access account user name 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 - Add in the OU of your AD
$dn = "OU=accounts,DC=domain,DC=com";

// Specify only those parameters we're interested in displaying from AD
$attrs = array("displayname","mail","samaccountname","telephonenumber","givenname", "title");
//$attrs = array("samaccountname");

// Create the filter from the search parameters
//$filter = "(|(givenName=".$_GET['q']."*) (sn=".$_GET['q']."*) (displayname=".$_GET['q']."*) (samaccountname=".$_GET['q']."*) (telephonenumber=".$_GET['q']."*))";
$filter = "(|(givenName=".$_GET['q']."*) (sn=".$_GET['q']."*) (displayname=".$_GET['q']."*) (samaccountname=".$_GET['q']."*))";

$search = ldap_search($ad, $dn, $filter, $attrs)
          or die ("<span class='LSstyle_noresults'><strong>Could not connect to AD</strong></span>");

// Sort entries by last name ('sn')
ldap_sort ( $ad, $search, 'sn' ) ;
//ldap_sort ( $ad, $search, $samaccountname ) ;

$entries = ldap_get_entries($ad, $search);

if ($entries["count"] > 0) {
for ($i=0; $i<$entries["count"]; $i++) {


echo "<span class='LSstyle'>Name: <strong><a href=\"mailto:".$entries[$i]["mail"][0]."\">".$entries[$i]["displayname"][0]." ".$entries[$i]["sn"][0]."</a></strong></span><br />";
echo "<span class='LSstyle'>Short name: <strong>".$entries[$i]["samaccountname"][0]."</strong></span><br />";
echo "<span class='LSstyle'>Phone: <strong>".$entries[$i]["telephonenumber"][0]."</strong></span><br />";
echo "<span class='LSstyle'>Title: <strong>".$entries[$i]["title"][0]."</strong></span><br />";
ech开发者_高级运维o "<span class='LSstyle'>Dept: <strong>".$entries[$i]["department"][0]."</strong></span></p>";
}
} else {
echo "<span class='LSstyle_noresults'><strong>No results found</strong></span>";
}
ldap_unbind($ad);
} 
?>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜