HelpSpot Help Desk Software | HelpSpot Blog | HelpSpot Support

Live Lookup Active Directory example bug


Apparently there is a bug in PHP where isset() returns TRUE even if the variable string is empty. Therefore, in the example code provided for Active Directory Live Lookups, if the first Lookup field is empty in the GET string, Live Lookup always returns every entry in the directory, because it sets the $filter variable to an empty string plus a *.

For example, if your first Lookup filter field is first_name, calling livelookup.php?pg=ajax_gateway&action=livelookup&rand=7OX9WT0V&first_name=&last_name=smith
always returns the entire directory because first_name is set, but it’s empty.

I fixed this by changing the isset() function to a !(empty()) function.
Here is an example:
if (!(empty($_GET[‘first_name’]))){

$filter = 'givenname='.$_GET['first_name'].'*';

}elseif (!(empty($_GET[‘email’]))){ //If no ID then try email

$filter = 'mail='.$_GET['email'].'*';

}elseif (!(empty($_GET[‘last_name’]))){ //If no ID or email then search on last name

$filter = 'sn='.$_GET['last_name'].'*';

} else $filter = ‘sn=’.’*’;

The final else statement is just a catch-all in case all fields are empty, it will return the whole directory (rather than a parse error).

Secondly, I had to change the cn ldap field to givenname for the first_name filter.


Thanks Adam! We’ll make the adjustments to the example.