1

I would like to create a registration page which takes user information and generates a user profile subdomain. Example www.UserName.Domain.com similar to posterous. I don't even know where to start, I'm guessing PHP forms with some server side scripts and something about wildcards... but thats just what i've turned up after several hours of googling...

I just starting off and not even sure of the best way to ask this question so thanks for you help.

Book Of Zeus
  • 49,509
  • 18
  • 174
  • 171
Justjoe
  • 371
  • 1
  • 4
  • 10
  • 1
    Do you have access to your domain's DNS server? And if so, does your provider support wildcard A or CNAME records? Cos if the answer to either of those is 'No', that's probably the end of the road unfortunately... – DaveRandom Aug 22 '11 at 22:48
  • 1
    Is this helpful for you? http://stackoverflow.com/questions/183928/how-to-let-php-to-create-subdomain-automatically-for-each-user – vascowhite Aug 22 '11 at 22:54

1 Answers1

4

First of all, make sure the domain (domain.tld - mydomain.com for example) goes to the folder with your PHP code.

<VirtualHost *:80>
    DocumentRoot "/my/path/"
    ServerName mydomain.com
    ServerAlias mydomain.com
    <Directory "/my/path/">
        allow from all
        Options +Indexes
    </Directory>
</VirtualHost>

Then on the PHP part simply use:

$urlParts = explode('.', $_SERVER['HTTP_HOST']);                                                                    
print_r($urlParts);

If you use: http://www.user.mydomain.com/ you will get:

Array
(
    [0] => www
    [1] => user
    [2] => mydomain
    [3] => com
)

which $urlParts[1] = your username

If you use: http://user.mydomain.com/ you will get:

Array
(
    [0] => user
    [1] => mydomain
    [2] => com
)

which $urlParts[0] = your username

Book Of Zeus
  • 49,509
  • 18
  • 174
  • 171