在创建用户注册子 [英] Create subdomain upon user registration

查看:103
本文介绍了在创建用户注册子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个网站,我想那注册以获得他们自己的子域的用户。此子是虚拟的,每个子域使用相同的Web服务器上的文件。

I have a website where I want users that sign up to get their own subdomain. This subdomain is virtual, and every subdomain uses the same web server files.

我使用PHP和Apache,我知道虚拟主机,但我不知道,我需要把虚拟主机code。首先,我没有获得的httpd.conf。其次,我想这自动登记时完成。

I use PHP and Apache, and I know about Virtual Hosts, but I'm wondering where I need to put the vhosts code. First, I don't have access to httpd.conf. Second, I want this to be done automatically upon registration.

我读过有关虚拟主机,但没有发现任何东西,回答我的问题。是否有任何人谁可以解释我这一切是如何一起工作,或知道在哪里可以找到我的答案?

I've read about virtual hosts, but didn't find anything that answers my questions. Is there anyone who can explain me how all this works together, or know where I can find my answers?

推荐答案

你能告诉Apache读一个额外的.conf文件? (传统存储您的虚拟主机在的httpd-vhosts.conf)

Can you tell apache to read an extra .conf file? (traditionally you store your vhosts in httpd-vhosts.conf)

如果是这样,添加类似以下内容并重新启动你的web服务器

if so, add something like the following and restart your webserver

NameVirtualHost *:80

<VirtualHost *:80>
        DocumentRoot /abs/path/to/webroot
        ServerName   domainname.com
        ServerAlias *.domainname.com
        <Directory /abs/path/to/webroot>
                AllowOverride All
                Order allow,deny
                Allow from all
        </Directory>
</VirtualHost>

然后在PHP中,你可以看到哪些子域用户通过检查要求:

then in php, you can see which subdomain the user is requesting by inspecting:

$_SERVER['HTTP_HOST']

IE浏览器。如果用户请求 http://user1.domainname.com/index.php

$ _ SERVER ['HTTP_HOST']将user1.domainname.com

$_SERVER['HTTP_HOST'] will have user1.domainname.com

您就可以爆炸('。',$ _ SERVER ['HTTP_HOST'])检查各段...等。

you can then explode('.', $_SERVER['HTTP_HOST']) to inspect each segment.. etc.

这篇关于在创建用户注册子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆