note 116606 added to ref.ldap

From: Date: Wed, 28 Jan 2015 11:47:05 +0000
Subject: note 116606 added to ref.ldap
Groups: php.notes 
Request: Send a blank email to php-notes+get-201544@lists.php.net to get a copy of this message
There is a lot of confusion about accountExpires, pwdLastSet, lastLogon and badPasswordTime active directory fields. All of them are using "Interval" date/time format with a value that represents the number of 100-nanosecond intervals since January 1, 1601 (UTC, and a value of 0 or 0x7FFFFFFFFFFFFFFF, 9223372036854775807, indicates that the account never expires): https://msdn.microsoft.com/en-us/library/ms675098(v=vs.85).aspx So if you need to translate it from/to UNIX timestamp you can easily calculate the difference with: <?php $datetime1 = new DateTime('1601-01-01'); $datetime2 = new DateTime('1970-01-01'); $interval = $datetime1->diff($datetime2); echo ($interval->days * 24 * 60 * 60) . " seconds\n"; ?> The difference between both dates is 11644473600 seconds. Don't rely on floating point calculations nor other numbers that probably were calculated badly (including time zone or something similar). Now you can convert from LDAP field: <?php $lastlogon = $info[$i]['lastlogon'][0]; // divide by 10.000.000 to get seconds from 100-nanosecond intervals $winInterval = round($lastlogon / 10000000); // substract seconds from 1601-01-01 -> 1970-01-01 $unixTimestamp = ($winInterval - 11644473600); // show date/time in local time zone echo date("Y-m-d H:i:s", $unixTimestamp) ."\n"; ?> Hope it helps. ---- Server IP: 72.52.91.14 Probable Submitter: 194.179.34.216 ---- Manual Page -- http://php.net/manual/en/ref.ldap.php Edit -- https://master.php.net/note/edit/116606 Del: integrated -- https://master.php.net/note/delete/116606/integrated Del: useless -- https://master.php.net/note/delete/116606/useless Del: bad code -- https://master.php.net/note/delete/116606/bad+code Del: spam -- https://master.php.net/note/delete/116606/spam Del: non-english -- https://master.php.net/note/delete/116606/non-english Del: in docs -- https://master.php.net/note/delete/116606/in+docs Del: other reasons-- https://master.php.net/note/delete/116606 Reject -- https://master.php.net/note/reject/116606 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#201544) next »