I am trying to build a little script that will tell me when certain fields in Active Directory are not populated. For example, in the below snippet, I want to retrieve all entries that do not have a phone number entered. How do you search for null with ldap?? Eventually I'll have criteria passed via an html form. BTW, I can bind and search for data that actually IN active directory
$host = "ldap://server.usa.domain.net";
$user = "user";
$pswd = "pass";
$ad = ldap_connect($host)
or die( "Could not connect!" );
ldap_set_option($ad, LDAP_OPT_PROTOCOL_VERSION, 3)
or die ("Could not set ldap protocol");
$bd = ldap_bind($ad, $user, $pswd)
or die ("Could not bind");
$dn = "OU=users,DC=usa,DC=domain,DC=net";
$attrs = array("displayname","mail","telephonenumber", "samaccountname");
$filter = "(telephonenumber=????)";
$search = ldap_search($ad, $dn, $filter)
or die ("ldap search failed");
$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 "Phone: ".$entries[$i]["telephonenumber"][0]."<br />";
echo "Email: ".$entries[$i]["mail"][0]."</p>";
echo "Username: ".$entries[$i]["samaccountname"][0]."</p>";
}
} else {
echo "<p>No results found!</p>";
}
ldap_unbind($ad);
?>