|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2000-07-03 11:38 UTC] stas at cvs dot php dot net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Oct 25 12:00:01 2025 UTC |
Hi! I'm writing a shop-solution for a company. One rule in this company is: All customers must be at least 18 years old. So I wrote a script with does the following: Get the bithdate and calculate the number of seconds s Get the curent date (in seconds since the Unix Epoch), substract 568036800 (on about 18 years in seconds). If the bithday in seconds is greater than current date minus 18 years (both in seconds) the customer is not 18 years old. Sorry for the long introduction, here's the bug: If I use dates in the area June 1914 and older my script allways says that the customer is too YOUNG! You can test it with the 2 files attached to this report: a.html ====== <FORM ACTION="a.phtml" METHOD=POST> Tag: <INPUT TYPE=text name="day"><BR> Monat: <INPUT TYPE=text name="month"><BR> Jahr:<INPUT TYPE=text name="year"><BR> <INPUT TYPE=submit> </FORM> a.phtml ======= <? $check_date = mktime(0, 0, 0, $month, $day, $year); print "Checkdate: $check_date<P>\n"; print "date(U): " . date("U") . "<P>\n"; $a = date("U") - 568036800; print "a: $a<P>\n"; if ($check_date > $a) print "to young"; else print "old enough"; $b = $a - $check_date; print "<P>\$a - \$checkdate: $b"; ?> E.g.: Given bithdate is (today: 01. July 2000) 15.6.1914 Then you'll get the following: Checkdate: -1752973200 date(U): 962487005 a: 394450205 old enough $a - $checkdate: 2147423405 Given bithday is 14.6.1914 Checkdate: -1753059600 date(U): 962487054 a: 394450254 zu jung $a - $checkdate: -2147457442 You can see that the 32-bit integer (signed) is overflowing. Ciao, Steffen