我有这个代码可以获取计算机的标签,operting系统和lastlogon时间戳。
问题在于我无法显示时间戳代码,因此人们可以理解它。
有没有办法在这段代码中实现这个?
<?php
header('Content-Type: text/html; charset=iso-8859-1');
$host = "ldap://server.server.net";
$user = "domain\user";
$pswd = "passw";
$ad = ldap_connect($host)
or die( "Could not connect!" );
ldap_set_option($ad, LDAP_OPT_PROTOCOL_VERSION, 3)
or die ("Could not set ldap protocol");
// Binding to ldap server
$bd = ldap_bind($ad, $user, $pswd)
or die ("Could not bind");
// Create the DN
$dn = "OU=NotebookM2,OU=WorkstationsM2,OU=PT1,DC=heiway,DC=net";
$attrs = array("cn","operatingsystem","lastlogon");
// Create the filter from the search parameters
$filter = $_POST['filter']."=".$_POST['keyword']."*";
$search = ldap_search($ad, $dn, $filter, $attrs)
or die ("ldap search failed");
$entries = ldap_get_entries($ad, $search);
if ($entries["count"] > 0) {
echo "<table border='1' width='100%'>";
echo "<tr>";
echo "<td>TAG:</td>";
echo "<td>OS:</td>";
echo "<td>Last Logon:</td>";
echo "</tr>";
for ($i=0; $i<$entries["count"]; $i++) {
echo "<tr>";
echo "<td>".$entries[$i]["cn"][0]."</td>";
echo "<td>".$entries[$i]["operatingsystem"][0]."</td>";
echo "<td>".$entries[$i]["lastlogon"][0]."</td>";
echo "</tr>";
}
echo "</table>";
} else {
echo iconv("UTF-8", "ISO-8859-1","<p>Ops Nothing Found</p>");
}
ldap_unbind($ad);
?>
答案 0 :(得分:0)
尝试使用此功能 添加此功能
function ldapTimeToUnixTime($ldapTime) {
$unixTime = 0;
/* LDAP time is assumed to start with "YYYYMMDDhhmmss" and to be in a
* Greenwith Meantime format.
*/
$pat = '/^([0-9]{4,4})([0-9]{2,2})([0-9]{2,2})([0-9]{2,2})([0-9]{2,2})' .
'([0-9]{2,2}).*/';
if(preg_match($pat, $ldapTime, $matches) > 0) {
$unixTime = gmmktime($matches[4], $matches[5], $matches[6],
$matches[2], $matches[3], $matches[1]);
}
return $unixTime;
}
替换
行echo "<td>".$entries[$i]["lastlogon"][0]."</td>";
带
$timestamp=ldapTimeToUnixTime($entries[$i]["lastlogon"][0]);
echo "<td>". gmdate("Y-m-d\TH:i:s\Z", $timestamp) ."</td>";