从$ _SERVER [Remote_User]中查找用户属性 - LDAP查询

时间:2014-07-01 17:58:36

标签: php ldap

当用户登录我的内部网站时,我想查询LDAP以根据OU查找其位置。这是我的代码:

<?php                                     
$ldap_host = "LDAP Server";
$username="Username";
$password="password";
$ldap_dn = "OU=OU,OU=OU,DC=php,DC=co"; 
$attr = array("physicalDeliveryOfficeName"); #filter for location

# Fix Username to exclude "Domain\"
$user = $_SERVER[REMOTE_USER];
$ua =  ltrim($user, 'Domain\\');  

# LDAP Connection
$ldap = ldap_connect($ldap_host) or die("Could not connect to LDAP");
@ldap_bind($ldap, $username , $password) or die("Could not bind to LDAP");

# Search Time.... search for attribute physicalDeliveryOfficeName
$search = ldap_search($ldap, $ldap_dn, "cn='$ua'", $attr); #filter correct?
$results = ldap_get_entries($ldap, $search);
echo $results["count"]; # did I get a hit??
echo $results[0]["physicalDeliveryOfficeName"][0];  #attempt to dump the actual attribute 
?> 

0 个答案:

没有答案