drn1008 2010-03-07 05:37
浏览 26
已采纳

在基于Linux的服务器中使用PHP创建动态子域

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?

  • 写回答

1条回答 默认 最新

  • dougao2830 2010-03-07 06:55
    关注

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

    • you do not have to register each user to your DNS server.
    • your DNS A-record may contain as few as 1 record: e.g *.mydomain.com -> 12.34.56.78
    • your web server at 12.34.56.78 have to be configured to accept wildcard

    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 
        // ...
    
    }
    
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 VUE项目怎么运行,系统打不开
  • ¥50 pointpillars等目标检测算法怎么融合注意力机制
  • ¥15 关于超局变量获取查询的问题
  • ¥20 Vs code Mac系统 PHP Debug调试环境配置
  • ¥60 大一项目课,微信小程序
  • ¥15 求视频摘要youtube和ovp数据集
  • ¥15 在启动roslaunch时出现如下问题
  • ¥15 汇编语言实现加减法计算器的功能
  • ¥20 关于多单片机模块化的一些问题
  • ¥30 seata使用出现报错,其他服务找不到seata