swett.bp swett.bp - 1 year ago 73
PHP Question

How can i get manager name from AD in php?

Now, i'm doing to connect my website to AD use ldap and get data from user logon but my problem is when user logon and i need to get manager name of user i get manager name by call

it's show data like this
i need to get only manager name that is 'rosie' but i don't know to get it, please help

this my code

$ldap_host ="servername";
$ldap_port = "port";
$ldap_dn = "OU=AllUser,DC=abc,DC=local";
$ldap_usr_dom = '@abc.local';
$ldap_it_group = "IT";
$ldap = ldap_connect($ldap_host,$ldap_port) or die("Could not connect to ".$ldap_host);
$bind = @ldap_bind($ldap, $user.$ldap_usr_dom, $password) or die("cant bind");
if($bind) {
$filter = "(&(objectClass=*)(sAMAccountName=".$user."))";
$attr = array("manager");
$result = ldap_search($ldap, $ldap_dn, $filter, $attr) or exit("Unable to search LDAP server");
$entries = ldap_get_entries($ldap, $result);
for ($i=0; $i<$entries["count"]; $i++) {
echo "Manager is: ". $entries[0]["manager"][0]."<p>";

Answer Source

A totally horrible way of doing it... doing regex would be better, but this is a quick hack job for ya, until the regex guys come around to provide the expression.

$manager = str_replace('CN=','',strstr($entries[0]["manager"][0],',',true));
echo "Manager is: ". $manager ."<p>";
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download