I have an Active Directory Server and an Apache Web Server. Both Servers have the correct date and time.
I use a PHP Script to show the last login and the last password reset of an user. That is working great, but both values show the time exactly two hours in the past. I do the password reset direct on the Active Directory Server, not via script.
I know, that the value "lastlogontimestamp" will only be refresh if it is greater than 14 days. So for testing this value, I create new users
I have no idea what's the problem and what I can do to solve this in a clean way. Of course, I could manually add two hours, but I think, this is' a clean way.
I hope anyone could help me.
Here is my code to get the last logon:
$lastLogonTimestamp = isset($userEntry['lastlogontimestamp']) ? $userEntry['lastlogontimestamp'][0] : 0;
$lastLogon = $lastLogonTimestamp != 0 ? date("Y-m-d H:i:s", intval($lastLogonTimestamp / 10000000 - 11644473600)) : 'N/A';
Here is my code, to get the last password reset:
$pwdLastSetTimestamp = isset($userEntry['pwdlastset'][0]) ? $userEntry['pwdlastset'][0] : 0;
if ($pwdLastSetTimestamp != 0) {
$unixTimestamp = (int)($pwdLastSetTimestamp / 10000000 - 11644473600);
$dateTime = DateTime::createFromFormat('U', (string)$unixTimestamp);
if ($dateTime instanceof DateTime && $dateTime->format('U') === (string)$unixTimestamp) {
$tag = $dateTime->format('d');
$monatIndex = (int)$dateTime->format('m') - 1;
$monatsnamen = ['Januar', 'Februar', 'März', 'April', 'Mai', 'Juni', 'Juli', 'August', 'September', 'Oktober', 'November', 'Dezember'];
$monat = $monatsnamen[$monatIndex];
$jahr = $dateTime->format('Y');
$uhrzeit = $dateTime->format('H:i');
$passwordLastSet = "$tag. $monat $jahr um $uhrzeit Uhr";
} else {
$passwordLastSet = 'Ungültiges Datum';
}
} else {
$passwordLastSet = 'N/A';
}