在基于Linux的服务器中使用PHP动态创建子域 [英] dynamic sub-domain creation with PHP in a linux based server

查看:57
本文介绍了在基于Linux的服务器中使用PHP动态创建子域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想即时使用PHP创建子域.假设用户将自己注册为名称"ABC".然后,我想通过PHP自动创建一个名为"ABC.mydomain.com"的子域.我正在使用基于Linux的服务器.

I want to create sub-domains using PHP on the fly. Suppose a user registers himself as a name "ABC". Then I want to create a sub-domain named 'ABC.mydomain.com' automatically by PHP. I'm using a linux based server.

有人会指出我正确的方向吗?

Would anyone point me to the right direction?

推荐答案

您应该意识到,使用通配符DNS记录可以轻松完成此操作.这样:

You should be aware that this is easily done using wildcard DNS records. This way:

  • 您不必将每个用户注册到您的DNS服务器.
  • 您的DNS A记录最多可包含1条记录:例如* .mydomain.com-> 12.34.56.78
  • 必须将您位于12.34.56.78的Web服务器配置为接受通配符

在服务器端脚本中,通过检查abc是否为现有的活动用户名来动态解析控制器/路由代码上的"abc.mydomain.com",示例代码如下:

In your server-side scripts, you dynamically resolve "abc.mydomain.com" on your controller/routing code by checking if abc is an existing active username, sample code below:

<?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 
    // ...

}

?>

这篇关于在基于Linux的服务器中使用PHP动态创建子域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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