AnchovyLegend
AnchovyLegend

Reputation: 12538

Giving users account access to for a certain amount of time?

I am working on an website where users will have to pay a small fee to create an account, and having an account will give them access to all of the features of the website for a certain amount of time, lets say 6 months.

Right now, I am using php to create user accounts using a mysql database to store user account info, and users can freely login/out for free, for an unlimited amount of time.

My question is, how would I go about setting a time limit on every account created, and once expired, give users the option to re-new their memebership?

Upvotes: 0

Views: 411

Answers (4)

TigerTiger
TigerTiger

Reputation: 10806

why don't you simply add an expired column in the user table and compare it with current date before you allow login - if this date has expired just redirect to a payment page to renew the membership?

You can also use this date to show "remaining days" for the active members and start showing payment link in the last few days or so.

I have always used DATETIME as column type to store the dates infor.

Have a look at MySQL date and time functions at http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html For example: The following query selects all rows with a date_col value from within the last 30 days:

SELECT something FROM tbl_name
    -> WHERE DATE_SUB(CURDATE(),INTERVAL 30 DAY) <= date_col;

What you need in your case is the following query to make memberships inactive -

$sql = SELECT * FROM users WHERE
DATEDIFF(expiration_date, CURDATE()) days_left
HAVING days_left < 0 

while($row=.....) {
//Update query to set user_status='expired' or whatever 
}

Upvotes: 1

Bhavesh G
Bhavesh G

Reputation: 3028

Add an extra column ex. expiry_time along with users info, then set it's value at the time of signup initially.

the account will expire when current time >= Expiry_time. and when the user want to re-new memebership then again re-set the expiry_time's value.

Upvotes: 0

pete
pete

Reputation: 25091

Store the date of account creation alongside the username in the MySQL DB. Check it on log in and expire it when 6 months have passed. Once expired, redirect users to a "renew your membership" page.

Upvotes: 0

HBv6
HBv6

Reputation: 3537

If you are using MySQL is very simple. Just add a column to the registration table that contains the expire date of the user.

Like this:

| id | username | expiration_date |
| 1  | test     | 1029384756      |

Then all you need to do is checking if time() (today) is >= expiration_date for the relative user. If so it's expired.

I used timestamp format for the expiration date, but you can use other formats...

Upvotes: 1

Related Questions