note 61144 deleted from ref.ldap by cmb

From: Date: Sun, 17 Nov 2019 08:35:15 +0000
Subject: note 61144 deleted from ref.ldap by cmb
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-213075@lists.php.net to get a copy of this message
Note Submitter: brudinie at yahoo dot co dot uk ---- LDAP Active Directory Last Logon (lastlogon). This took me an entire day to work out. If you want to get the last logon date from an active directory account, you have to convert it from AD time stamp to unix time stamp. Once you've got a unix time stamp, PHP can format it as a date. Here is the code to do it: $dateLargeInt=$info[$i]["lastlogon"][0]; // nano seconds (yes, nano seconds) since jan 1st 1601 $secsAfterADEpoch = $dateLargeInt / (10000000); // seconds since jan 1st 1601 $ADToUnixConvertor=((1970-1601) * 365.242190) * 86400; // unix epoch - AD epoch * number of tropical days * seconds in a day $unixTsLastLogon=intval($secsAfterADEpoch-$ADToUnixConvertor); // unix Timestamp version of AD timestamp $lastlogon=date("d-m-Y", $unixTsLastLogon); // formatted date

« previous php.notes (#213075) next »