-1

I'm working on an app which has a set of features. I want to restrict every feature based on the subscription package that the user opted.

For example:

Let's say i have three subscription types:

1) Bronze - Free User
2) Silver 
3) Gold

And i have three features:

1) Create additional user accounts
2) Create a group

Now i want users with Silver and Gold to have access to feature 1. And only users with Gold subscription given access to feature 2.

What could be the best way to implement this in PHP and database (Mysql).

Thanks,
Sash

Pruthvi Raj Nadimpalli
  • 1,335
  • 1
  • 15
  • 30
  • what you have tried so far? – ɹɐqʞɐ zoɹǝɟ May 25 '14 at 06:11
  • Working elegant code would be the best. Working (but poorly written) code would be second - all the way down to non-working code which would be an equal last. Have you tried anything so far? – Fluffeh May 25 '14 at 06:11
  • heres something to consider http://stackoverflow.com/questions/1380045/why-should-i-use-bitwise-bitmask-in-php – Tom May 25 '14 at 06:18

1 Answers1

1

The way I would set it up is...

In MySQL you have the following tables: users, subscriptions, features, subscriptions_features, and users_subscriptions

users_subscriptions has two columns user_id and subscription_id subscriptions_features as two columns subscription_id and feature_id

With this structure you will know the user->subscriptions->features, then on any restricted pages you check if the user has the required subscriptions etc.

This is a little off-topic, but....

You could save a lot of time designing an application like this by using the Symfony2 framework because it is designed to enable you to build and scaffold a prototype of this sort of thing in minutes, once you get the hang of it. If you don't get a kick out of this quick tutorial, I'll eat my hat.

Fo.
  • 3,752
  • 7
  • 28
  • 44