PHP and Active Directory
Posted: Tue Aug 30, 2005 1:41 pm
I've found the following code, but I can't see to get it to work. I'm running this on a Windows 2000 with IIS Server. Do I use my windows user and pass? What do I use for accoutn suffix and base dn? Could some one shows me how? Please see in bold.
Part of the adLDAP Class
Code: Select all
//include the class
require_once("adLDAP.php");
//create the LDAP connection
$adldap = new adLDAP();
//variables, change these
[b]$user="John";
$pass="John";[/b]
$userlookup = "another_username";
$group="group_name";
//authenticate a user
if ($adldap -> authenticate($user,$pass)){
echo ("Authenticated ok!<br><br>\n");
// User Information
$info=$adldap->user_info($userlookup,$fields);
echo "User Information:";
echo ("<pre>"); print_r($info); echo ("</pre>\n");
// Users's Groups
$info=$adldap->user_groups($userlookup);
echo "User's Groups: (". count($info) ."):";
echo ("<pre>"); print_r($info); echo ("</pre>\n");
// All Users
$info = $adldap->all_users(true);
echo "All Users: (". count($info) .")";
echo "<pre>"; print_r($info); echo "</pre>\n";
// All Groups
$info = $adldap->all_groups(true);
echo "All Groups: (". count($info) ."):";
echo "<pre>"; print_r($info); echo "</pre>\n";
//check to see if they're a member of a group
if ($adldap -> user_ingroup($userlookup,$group)){
echo ("SUCCESS! User is a member of group: ".$group);
} else {
echo ("FAILED! User is not a member of group: ".$group);
}
} else {
echo ("Authentication failed!");
}
?>Code: Select all
class adLDAP {
// You will need to edit these variables to suit your installation
[b] var $_account_suffix="@mydomain.local";
var $_base_dn = "DC=mydomain,DC=local"; [/b]
// An array of domain controllers. Specify multiple controllers if you
// would like the class to balance the LDAP queries amongst multiple servers
var $_domain_controllers = array ("dc.mydomain.local");
// optional account for searching
var $_ad_username=NULL;
var $_ad_password=NULL;