0

I am looking for a solution for develop user registration system with creating sub domain for each user, e.g.

My domain is

www.example.com

When a user creates an account he could be able to access that created account at

www.user_name.example.com

I am trying to do this in PHP.

What is the best approach to do this kind of login system?

If you know any tutorial(s) it will be great help for me.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Umanda
  • 4,737
  • 3
  • 23
  • 28
  • 1
    Not sure of my answer so I post as comment, but I would do it with virtualhosts and ServerPath with a rewrite rule to pass parameter to PHP http://httpd.apache.org/docs/current/vhosts/examples.html#serverpath – Jonathan Muller Nov 19 '13 at 16:24

1 Answers1

2

In your DNS server:

*.example.com.   3600  A  127.0.0.1

In your Apache VirtualHost configuration:

ServerAlias *.example.com

In your code:

$match = preg_match(
    '/^www\.(.+)\.example.com$/', 
    $_SERVER['HTTP_HOST'], 
    $matches
);

if ($match) {
    $user_name = $matches[1];
    //stuff when dynamic subdomain detected
}

For more details you can see this.

Community
  • 1
  • 1
evalarezo
  • 1,134
  • 7
  • 13