1

Currently, I'm working with a website. This website is written using PHP with PostgreSQL as the back-end. For the server I use Apache (XAMPP). My website has a membership feature consist of free membership and premium membership. Premium membership valid for 1 year after the registration, after that the user membership will be revert back to free membership. To be a premium membership again, the user should pay the membership fee and the account will be upgraded again for the next 1 year (imagine Rapidshare membership!). How to create a automation process to check and demote an expired membership? I think it should be a background process working on the back-end (postgresql), but I'm not really sure. Any idea or solution?

Big thanks :)

3 Answers 3

1

An idea would be like this:

  • User pays for premium
  • Script inserts an entry in a database with premium cancelling dates, with cancelling date and user FK
  • A daily cron/at(depending on OS) job searches the db for cancelling dates with the date of today, and cancels the respective users' premium membership

I hope it helps you :)

Sign up to request clarification or add additional context in comments.

3 Comments

Hmm, but how can I make it when the web hosting is not on my office? I used 3rd party web hosting. Though I paid for its service, I'm afraid that they don't give me privilege to access their cron...
@GuyFreakz If you can't do this, you could try something like in jmz's answer
As far as I know, SQL Server have an ability to handle background process. I was once read an online article about someone delete inactive member account from his database automatically, but I forget, where I read it. For now, I've done what jmz suggest. Thanks!
1

Use a table schema like this one:

CREATE TABLE all_accounts (
    id INTEGER NOT NULL PRIMARY KEY,
    premium_expires DATE NOT NULL DEFAULT current_date,
    other_attrs,
    ...
);

Then create a view which you use for queries:

CREATE VIEW accounts AS
SELECT
   account.*, current_date < account.premium_expires AS is_premium_membership
FROM
   account
WHERE 
   id = ?

Now a select to accounts will yield an is_premium_membership attribute which is t when the premium membership is valid. No need for background jobs.

1 Comment

For now, that's what I did ;p
1

Why don't you check every time when user logs in?

1 Comment

well what if the user stays logged in for two weeks or so? I know I haven't logged out of gmail (for example) for 1 month or so

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.