Forum Discussion
maurox_59221
Nimbostratus
Oct 22, 2013Ldap query from ltm
Hi all,
I'm searching an irule that would direct all the authenticated users (that belong to a specific group defined on the ldap profile/object) to a specific pool.
All the others users (that aren't...
Kevin_Stewart
Employee
Oct 28, 2013Okay, let's say you have a PHP web server that can make LDAP calls based on a parameter in the query string (ex. "?find=user"). Example:
set_time_limit(30);
error_reporting(E_ALL);
ini_set('error_reporting', E_ALL);
ini_set('display_errors',1);
$ldapserver = '10.80.0.200';
$ldapuser = 'CN=Administrator,CN=users,DC=mydomain,DC=com';
$ldappass = 'password';
$ldaptree = "CN=Users,DC=mydomain,DC=com";
if(!isset($_REQUEST["find"])) {
echo "No query parameter";
} else {
// query string parameter to use in search
$findthis = $_REQUEST["find"];
// what value(s) to return
$justthese = array("userPrincipalName");
$ldapconn = ldap_connect($ldapserver) or die("Could not connect to LDAP server.");
if($ldapconn) {
$ldapbind = ldap_bind($ldapconn, $ldapuser, $ldappass) or die ("Error trying to bind: ".ldap_error($ldapconn));
if ($ldapbind) {
$result = ldap_search($ldapconn,$ldaptree, "(sAMAccountName=$findthis)", $justthese) or die ("Error in search query: ".ldap_error($ldapconn));
$data = ldap_get_entries($ldapconn, $result);
if($data["count"] > 0) {
echo $data[0]["userprincipalname"][0];
} else {
echo "No data";
}
} else {
echo "LDAP bind failed...";
}
}
ldap_close($ldapconn);
}
** Ref: http://www.php.net/manual/en/function.ldap-search.php
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)Recent Discussions
Related Content
DevCentral Quicklinks
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com
Discover DevCentral Connects