开发者

Generate Subdomain From PHP form

开发者 https://www.devze.com 2023-03-30 03:17 出处:网络
I would like to create aregistration pa开发者_StackOverflowge which takes user information and generates a user profile subdomain. Example www.UserName.Domain.com similar to posterous. I don\'t even k

I would like to create a registration pa开发者_StackOverflowge 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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消