我正在尝试使用LDAP PHP获取Active Directory中的用户ID。我刚刚为服务器上的用户添加了一个使用vb脚本的员工ID字段,并且可以在那里看到AD上的employeeID。 但是当我尝试为同一个用户获取员工ID时,它不显示,而其他属性显示出来。以下是我的代码。 我是新手。任何帮助将不胜感激。
enter code here
<?php
$partialState = $_POST['partialState'];
ini_set('display_errors', 0);
error_reporting(E_ERROR | E_WARNING | E_PARSE);
if(!empty($_POST['partialState'])) {
$username1="****";
$password1="*****";
$adServer = "ldap://*******";
$ldap = ldap_connect($adServer);
$username = $username1;
$password = $password1;
$ldaprdn = '***' . "\\" . $username;
ldap_set_option($ldap, LDAP_OPT_PROTOCOL_VERSION, 3) or die ("Could not set ldap protocol");
ldap_set_option($ldap, LDAP_OPT_REFERRALS, 0);
$bind = @ldap_bind($ldap, $ldaprdn, $password);
if ($bind) {
echo "binded";
$dn = "DC=***,DC=**,DC=**" ;
$filter= "(&(objectCategory=person)(displayname=*$partialState*)(employeeID=*))";
$justthese = array("displayname","department" , "title", "whenCreated","employeeID");
$result = ldap_search($ldap,$dn , $filter ,$justthese) or die ("Search failed");
$info = ldap_get_entries($ldap, $result);
for ($i=0; $i < $info["count"]; $i++) {
echo "Name: ".$info[$i]["displayname"][0]."<br>\n";
echo "Department: ".$info[$i]["department"][0]."<br>\n";
echo "Title: ".$info[$i]["title"][0]."<br>\n";
echo "EmployeeID: ".$info[$i]["employeeID"][0]."<br>\n";
$date = $info[$i]["whencreated"][0];
// Get the date segments by splitting up the LDAP date
$year = substr($date,0,4);
$month = substr($date,4,2);
$day = substr($date,6,2);
$hour = substr($date,8,2);
$minute = substr($date,10,2);
$second = substr($date,12,2);
// Make the Unix timestamp from the individual parts
$timestamp = mktime($hour, $minute, $second, $month, $day, $year);
// Output the finished timestamp
print "Date Created : ".$month."/".$day."/".$year. "\n";
echo "<div class='archievebox'><a href=''>View Details</a></div>";
echo "<hr>";
}
ldap_free_result($result);
ldap_unbind($ldap);
}
}
?>
答案 0 :(得分:0)
ldap_get_entries返回的数组中的键(属性名称)都被转换为小写。所以没有关键的“employeeID”而是“employeeid”。
当var_dump返回的数组时,您应该能够看到这一点。