【发布时间】:2010-03-07 14:55:49
【问题描述】:
我想使用 PHP 即时创建子域。假设用户将自己注册为名称“ABC”。然后我想通过 PHP 自动创建一个名为 'ABC.mydomain.com' 的子域。我正在使用基于 linux 的服务器。
有人能指点我正确的方向吗?
【问题讨论】:
我想使用 PHP 即时创建子域。假设用户将自己注册为名称“ABC”。然后我想通过 PHP 自动创建一个名为 'ABC.mydomain.com' 的子域。我正在使用基于 linux 的服务器。
有人能指点我正确的方向吗?
【问题讨论】:
您应该知道,使用通配符 DNS 记录很容易做到这一点。这样:
在您的服务器端脚本中,您可以通过检查 abc 是否是现有的活动用户名来动态解析控制器/路由代码上的“abc.mydomain.com”,示例代码如下:
<?php
// Note that I am using SERVER_NAME vs HTTP_HOST,
// but for additional safety also check your httpd.conf
list($user, $domain) = split("\.", $_SERVER['SERVER_NAME'], 2);
// check if domain is correct,
// or you can leave this part if the web server checks this already
if ($domain === "mydomain.com") {
// here, you verify $user if existent/active
// and reroute or render the page depending on request params
// ...
}
?>
【讨论】: