Welcome Guest, Not a member yet? Register   Sign In
Wildcard subdomains and primary keys
#1

[eluser]Davva[/eluser]
Hi,
Let me just start by saying that I am not a pro developer, but I'm not a newbie either. I've created many database driven web sites using asp/php.

I am working on a prototype for a web site/service. I am using codeigniter/mysql. The basic functionality of the site will be to let people manage freelance projects. Let's call the site "myprojects.com" (there is no real name yet).

With this project, I am somewhat stuck with two problems that I never had to deal with before.

1. Subdomains for each account
Every new account should have its own subdomain. Obviously, I want this process automated, so that whenever a new account is registered, the subdomain is created/available on the fly. I am thinking somewhere along the lines of having a wildcard for subdomains and let the php code determine which subdomain was requested. Having "extracted" the subdomain, I can then access the relevant content for the user. This way, I never really have to create a subdomain for each account, I just maintain a table with account names that maps to the subdomain...

What do you think, is this a good solution?

2. Primary keys starting at 1 for each account
Let's suppose I have just registered a new account named "superman". I would access the account via superman.myprojects.com.

Now I create my first project. The project id (primary key) would be 1. If I create another project, it will have id=2 and so on.

-> superman.myprojects.com/project/1
-> superman.myprojects.com/project/2

In this scenario, all projects for all accounts would be stored in the same table named "projects". Each project would have a foreign key connected to the account id for which the project was created.

Now a second account is created, "ironman". When a new project is created for this account, it will have id=3, because superman already have two projects with id 1 and 2.
-> ironman.myprojects.com/project/3 => ironman's first project.

It would be nice to let each account start their ids at 1. But for this to be possible, I need to create a new db for each account. Is this really the best way to accomplish this? It seems a bit "clunky" and redundant, and also hard to manage as the number of accounts increase.

How would you go about setting this up? Any thoughts/help is greatly appreciated!

// David




Theme © iAndrew 2016 - Forum software by © MyBB