Search code examples
phpldap

setting accountexpires date with PHP and LDAP


I'm having trouble setting the 'accountexpires' and wondered if anyone knows a way around it, I believe it's because I have a 18 digit number. I have a form where someone sets a date, I need to set the account to expire then, if I provide the number as a hardcoded string it works, but I cannot convert the finished calculation to a string. Anyone know any way around this? thanks.

<?php
$currentTimeUnix = 1442383989; //this will vary depending on user's input
$secondsBetween1601and1970 = 11644473600;
$timesAdded = $currentTimeUnix + $secondsBetween1601and1970;// comes to 13086857589
$nanoseconds = $timesAdded * 10000000; //comes to 130868575890000000
echo $nanoseconds; //displays 1.3086857589E+017
echo (string)$nanoseconds; //displays 1.3086857589E+017
echo strval($nanoseconds); //displays 1.3086857589E+017
?>

Solution

  • PHP is kind of bad with large numbers but sprintf can help. try:

    echo sprintf( '%018.0f', $nanoseconds );
    -> 130868575890000000
    

    Alternatively you change the "precision" setting where precision is described:

    precision integer

    The number of significant digits displayed in floating point numbers.
    
    ini_set("precision",20);
    echo $nanoseconds;
    -> 130868575890000000