views:

54

answers:

3

Hello,

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 :)

+1  A: 
Gabi Purcaru
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
@GuyFreakz If you can't do this, you could try something like in jmz's answer
Gabi Purcaru
@Gabi: 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!
GuyFreakz
A: 

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.

jmz
For now, that's what I did ;p
GuyFreakz
+1  A: 

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

ilhan
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
Gabi Purcaru
that's right Gabi...
GuyFreakz