user198729
user198729

Reputation: 63636

How to implement real time sub domain in PHP?

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?

Upvotes: 3

Views: 460

Answers (3)

MiB
MiB

Reputation: 143

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

Upvotes: 2

knoopx
knoopx

Reputation: 17400

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

Basic DNS/Apache setup:

App-side logic (crappy code):

Upvotes: 2

Franz
Franz

Reputation: 11553

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.

Upvotes: 6

Related Questions