9 Replies Latest reply on Mar 31, 2009 12:16 AM by 921creative

    Account Expiration - How Does It Work?

    921creative Level 1
      Can someone please explain how account expiration with ADDT works? I know there is a registration date column and an expiration column. If you put 365 into the expiration column, does that mean the account will expire 365 days from what is in the registration date column? When the account expires, what happens - does the "active" column automatically change so the user is then inactive? Is there a way to display how many days a user has remaining before their account expires?

      Sorry if this is a basic concept, but I haven't seen it explained anywhere yet. Thanks!

      Brian
        • 1. Re: Account Expiration - How Does It Work?
          Albert S. Level 3
          Hi AdobeBrian,

          From the manual:

          In the Default expiration interval text field enter the interval, in days, for which the account is active. After this period passes, the user is no longer allowed access.

          ---
          Is there a way to display how many days a user has remaining before their account expires?
          ---
          //function
          function daysDifference($endDate, $beginDate)
          {
          //explode the date by "-" and storing to array
          $date_parts1=explode("-", $beginDate);
          $date_parts2=explode("-", $endDate);
          //gregoriantojd() Converts a Gregorian date to Julian Day Count
          $start_date=gregoriantojd($date_parts1[1], $date_parts1[2], $date_parts1[0]);
          $end_date=gregoriantojd($date_parts2[1], $date_parts2[2], $date_parts2[0]);
          return $end_date - $start_date;
          }

          //usage
          $regDate = '2009-10-10'; //Replace with your registration date from database.
          $today = date("Y-m-d");
          echo daysDifference($regDate,$today);
          • 2. Re: Account Expiration - How Does It Work?
            921creative Level 1
            Albert: Thanks! This is what I was looking for. However, I'm not sure where in the page is the best place to put the function code. I put it towards the top and the page doesn't load. And, do you declare the 2 variables ($regDate and $today) alongside the echo statement or should those be elsewhere on the page? (Obviously I've never added my own functions in before!)

            Brian
            • 3. Re: Account Expiration - How Does It Work?
              Albert S. Level 3
              Hi Brian, <br /> <br />The function and $today can go anywhere above the HTML and above $daysLeft within the closing and opening tags of php <br /> <br /><?php<br />//Calculate days between dates<br /><br />function daysDifference($endDate, $beginDate)<br />{<br />   //explode the date by "-" and storing to array<br />   $date_parts1=explode("-", $beginDate);<br />   $date_parts2=explode("-", $endDate);<br />   //gregoriantojd() Converts a Gregorian date to Julian Day Count<br />   $start_date=gregoriantojd($date_parts1[1], $date_parts1[2], $date_parts1[0]);<br />   $end_date=gregoriantojd($date_parts2[1], $date_parts2[2], $date_parts2[0]);<br />   return $end_date - $start_date;<br />}<br />$today = date("Y-m-d"); <br />?>. <br /> <br />---- <br /> <br />$regDate and $daysLeft will need to go after your record set. <br /> <br />$regDate = $row_rsData['registrationdate_usr']; <br />$daysLeft = daysDifference($regDate,$today); <br /> <br />Then echo $daysLeft within the HTML <br />How many days left: <?php echo $daysLeft; ?>
              • 4. Re: Account Expiration - How Does It Work?
                921creative Level 1
                Thanks Albert, getting there. At least my page loads now. I did all as you suggested but the output of the echo statement ends up being Account expires in 2454865 days! Obviously there is some problem with the calendar conversion. Any idea what the problem might be exactly?
                • 5. Re: Account Expiration - How Does It Work?
                  Albert S. Level 3
                  Hi Brian,

                  I was kinda tired when I grabbed that code and edited it.

                  $regDate should actually be the account expiration column data not the registration date column.

                  Can you verify that the expiration date is being added to the database or is it just entering 0000-00-00 00:00?
                  • 6. Re: Account Expiration - How Does It Work?
                    Albert S. Level 3
                    Hi Brian,

                    I just did some checking into the expiration process. Sorry for the previous code.
                    Here is something that should work.

                    The expiration date column only holds the number of how many days, not an actual date. So here we go.

                    • 7. Re: Account Expiration - How Does It Work?
                      921creative Level 1
                      It's still not working. The echo output is 2455283. In the table, my registration date column is called mem_regdate and my expiration column is called mem_exp. The registration date is 2009-03-27. The expiration is set to 365 (so it expires after one year). It's almost like the only calculation that's being performed is multiplication!

                      I put the function code directly before the DOCTYPE declaration in its own set of
                      • 8. Re: Account Expiration - How Does It Work?
                        Albert S. Level 3
                        Hi Brian, <br /> <br />I see a typo here: <br /> <br />$row_rsmembers = mysql_fetch_assoc($rsmembers); <br /> <br />Should be: <br /> <br />$row_rsMembers = mysql_fetch_assoc($rsmembers); <br /> <br />Since thru the rest of the script you are using a capital M to call the data: <br /> <br />$row_rsMembers['mem_exp'] <br /> <br />Also as a test you can paste the code below into a blank php page and run it. The problem I think has to do with the dynamic values not having the right data or the problem above, a typo. Below is the same script with static values in $regDate and $expDays. <br /> <br /><?php //Calculate days between dates<br /><br />function daysDifference($endDate, $beginDate)<br />{<br />   //explode the date by "-" and storing to array<br />   $date_parts1=explode("-", $beginDate);<br />   $date_parts2=explode("-", $endDate);<br />   //gregoriantojd() Converts a Gregorian date to Julian Day Count<br />   $start_date=gregoriantojd($date_parts1[1], $date_parts1[2], $date_parts1[0]);<br />   $end_date=gregoriantojd($date_parts2[1], $date_parts2[2], $date_parts2[0]);<br />   return $end_date - $start_date;<br />}<br />$today = date("Y-m-d");<br /><br />$regDate = strtotime('2009-01-01'); // Registration date<br />$expDays = "365"; // Amount of days before expired<br />$findExpDate = $regDate + (60*60*24*$expDays); // adds days to registration date<br />$reFormatDate = date('Y-m-d', $findExpDate); // Reformats date<br />$daysLeft = daysDifference($reFormatDate,$today); // Calculates days left<br />?> <br /><?php<br /><br />echo $reFormatDate."---"; // Date of expire<br /><br />echo $daysLeft; // Days Left<br /><br />?>
                        • 9. Re: Account Expiration - How Does It Work?
                          921creative Level 1
                          Albert - Success! It worked. I had been trying to put the variable declarations along with what I thought was the recordset within the code, but when I put it all together with the function, it works. On the lowercase "m" - that is actually from the transaction recordset which is automatically created when I add an Update transaction to the page.

                          Thanks so much for your time and help!