$name = IMPORTUSER;
$pass = IMPORTPASSWORD;
$adServer = ADSERVER;
$ldapconn = ldap_connect($adServer) or die("Could not connect to LDAP server.");
ldap_set_option($ad, LDAP_OPT_PROTOCOL_VERSION, 3) or die ("Could not set ldap protocol");
ldap_set_option($ad, LDAP_OPT_REFERRALS, 0) or die ("Could not set option referrals");
$account = $name;
$password = $pass;
$ldaprdn = $account.USERDOMAIN;
$ldappass = $password;
if ($ldapconn) {
$ldapbind = ldap_bind($ldapconn, $ldaprdn, $ldappass) or die("Couldn't bind to AD!");
}
$dn = ADDN;
$filter="(|(sn=*))";
$justthese = array("displayname", "mail", "company", "department", "physicaldeliveryofficename", "mobile", "ipphone", "telephonenumber", "facsimiletelephonenumber", "streetaddress", "l", "st", "postalcode", "c", "title", "samaccountname", "useraccountcontrol");
$sr=ldap_search($ldapconn, $dn, $filter, $justthese);
$info = ldap_get_entries($ldapconn, $sr);
for ($i=0; $i < $info["count"]; $i++) {
if ($info[$i]["useraccountcontrol"][0] == "66050") {
echo "Name: ".$info[$i]["displayname"][0]."<br>\n";
echo "Email: ".$info[$i]["mail"][0]."<br>\n";
echo "Company: ".$info[$i]["company"][0]."<br>\n";
echo "Department: ".$info[$i]["department"][0]."<br>\n";
echo "Location: ".$info[$i]["physicaldeliveryofficename"][0]."<br>\n";
echo "Mobile: ".$info[$i]["mobile"][0]."<br>\n";
echo "Extenstion: ".$info[$i]["ipphone"][0]."<br>\n";
echo "Office: ".$info[$i]["telephonenumber"][0]."<br>\n";
echo "Fax: ".$info[$i]["facsimiletelephonenumber"][0]."<br>\n";
echo "Street: ".str_replace(",","",$info[$i]["streetaddress"][0])."<br>\n";
echo "City: ".$info[$i]["l"][0]."<br>\n";
echo "State: ".$info[$i]["st"][0]."<br>\n";
echo "Postal Code: ".$info[$i]["postalcode"][0]."<br>\n";
echo "Country: ".$info[$i]["c"][0]."<br>\n";
echo "Title: ".$info[$i]["title"][0]."<br>\n";
echo "Username: ".$info[$i]["samaccountname"][0]."<br>\n";
echo "Account Status: ".$info[$i]["useraccountcontrol"][0]."<br>\n";
echo "<hr>";
}
}
ldap_free_result($sr);
ldap_unbind($ldapconn);