I have been using the following code all 2008 , it checks if user is active, check last activation date, number of months paid, add that time to the last activation date and also check if date is grater than actual date.
It worked great until Jan 1st, when I guess there's a problem with users with active accounts on 2008 and months calculation with 2009
Code: Select all
$myrow = mysql_fetch_array($result);
$date_activation = $myrow['start_date']; // Sample date: "2008-12-18 08:00:47"
$months = $myrow['type']; // Sample value = 1 (means 1 month) or 12 means 12 months
$date_now = date("Y-m-d h:m:s", time());
$qty_years=floor($months/12);
$qty_months=$months%12;
$bits=explode("-",$date_activation);
$year=$bits[0];
$month = sprintf('%02d',$bits[1]);
$newyear=$year+$qty_years;
$newmonth=sprintf('%02d', $month+$qty_months);
$date_expires=$newyear."-".$newmonth."-".$bits[2];
if ($date_now <= $date_expires)
{
// user is active, write a cookie and say welcome
} else {
// subscription expired
}