tags:

views:

83

answers:

3

Suppose domain is domain.name,

after a new user sign up,need to generate a new domain:user1.domain.name.

How to implement it?

BTW,is there a limit for the number of sub domains?

+5  A: 

I would simply use a wildcard to point all subdomains to a certain directory and have a front controller there that determines the used one from the URL - this is the easiest and safest solution from PHP.

EDIT Then you can obviously check whether that one should be existing (store them in a database or whatever) etc.

Franz
Can you be more specific about `determines the used one from the URL`
The domain is in `$_SERVER['HTTP_HOST']`. Not sure if there are any exceptions to this case, though. Then you can just explode the string by dots and off you go.
Franz
+1  A: 

What you are asking for is known as Wildcard DNS record:

Basic DNS/Apache setup:

App-side logic (crappy code):

knoopx
* there is no need of domain generation and there is no limit of subdomains
knoopx
+1  A: 

Subdomains can be retrieved with .htaccess (you need however wildcard mentioned earlier in this thread):

RewriteEngine On
RewriteCond %{HTTP_HOST} ^user([0-9]{1,10}).domain.name$
RewriteRule ^.*$ index.php?subdomain=%1
MiB