SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member rdyco's Avatar
    Join Date
    Mar 2013
    Location
    US
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Site Membership Expiration Date?

    This is my first time using MySQL and I want to create a membership site. This is the table I outlined so far:

    user_id
    username
    password
    email
    registration_date
    subscription
    membership_date

    When users of my site pays for a month of subscription, I want to set membership_date to date when they subscribed. Then after that, do I check if their date has expired every time they log in?

    What I thought of doing is maybe perform a check when they are logged in and visit the site to see if membership_date + 31 is greater than today's date, if so, then deactivate membership by changing subscription to false.

    Something like this...
    Code:
    if membership_date  + 31 > today's date
    then assign FALSE to subscription
    How can I find out the common and secure way to go about this?

  2. #2
    SitePoint Member
    Join Date
    Apr 2013
    Posts
    8
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    You could set up a cron job, It would check in specified interval if any of the users have subscription expired and update records if they do. Perhaps per hour or per day should be enough.

    Your approach also works fine.

    You can also take a look at some modules from open source CMS solutions that provide subscription functionality and learn from their code.

  3. #3
    rajug.replace('Raju Gautam'); bronze trophy Raju Gautam's Avatar
    Join Date
    Oct 2006
    Location
    Kathmandu, Nepal
    Posts
    4,013
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by rdyco View Post
    This is my first time using MySQL and I want to create a membership site. This is the table I outlined so far:

    user_id
    username
    password
    email
    registration_date
    subscription
    membership_date

    When users of my site pays for a month of subscription, I want to set membership_date to date when they subscribed. Then after that, do I check if their date has expired every time they log in?

    What I thought of doing is maybe perform a check when they are logged in and visit the site to see if membership_date + 31 is greater than today's date, if so, then deactivate membership by changing subscription to false.

    Something like this...
    Code:
    if membership_date  + 31 > today's date
    then assign FALSE to subscription
    How can I find out the common and secure way to go about this?
    I would recommend you to use the condition in the query itself:
    Code mysql:
    SELECT tm.*,
    	(CASE 
    		WHEN CURRENT_DATE < DATE_ADD(tm.membership_date, INTERVAL 31 DAY) THEN 'YES'
    		ELSE 'NO'
    	END) AS expired_flag
    FROM tbl_members AS tm
    WHERE username='yourpassword' AND `password`='yourpassword';

    Now you can check in PHP whether the logged in user's date has expired or not.

    Either you can do it in PHP itself, see strtotime() for this.
    Mistakes are proof that you are trying.....
    ------------------------------------------------------------------------
    PSD to HTML - SlicingArt.com | Personal Blog | ZCE - PHP 5


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •