【问题标题】:LDAP Fetch Employee ID using PHPLDAP 使用 PHP 获取员工 ID
【发布时间】:2016-05-30 15:54:40
【问题描述】:

我正在尝试使用 LDAP PHP 在 Active Directory 中获取用户的员工 ID。我刚刚使用 vb 脚本为服务器上的用户添加了一个员工 ID 字段,并且可以在那里看到 AD 上的员工 ID。 但是,当我尝试为同一用户获取员工 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); 
}

}
?>

【问题讨论】:

    标签: php ldap ldap-query


    【解决方案1】:

    ldap_get_entries 返回的数组中的键(属性名)全部转换为小写。所以没有键“employeeID”而是“employeeid”。

    当您 var_dump 返回的数组时,您应该能够看到这一点。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-09-24
      • 1970-01-01
      • 1970-01-01
      • 2022-06-16
      • 1970-01-01
      相关资源
      最近更新 更多