1

我想知道如何为我的数据库中的每个用户设置一个自动和轻量级的 PHP 创建子域?那可能吗 ?

4

2 回答 2

2
<?php
$domainName = 'example.com';
    $subDomainName =  'demo';
     $subDomain = $subDomainName;
    $cPanelUser = 'cpanel_user_name';
    $cPanelPass = 'cpanel_pass';
    $rootDomain = $domainName;
    
    $buildRequest = "/frontend/paper_lantern/subdomain/doadddomain.html?rootdomain=" . $rootDomain . "&domain=" . $subDomain . "&dir=public_html/$domainName/$subDomain";
      
    $openSocket = fsockopen('localhost',2082);
    if(!$openSocket) {
    return "Socket error";
    exit();
    }
    
    $authString = $cPanelUser . ":" . $cPanelPass;
    $authPass = base64_encode($authString);
    $buildHeaders  = "GET " . $buildRequest ."\r\n";
    $buildHeaders .= "HTTP/1.0\r\n";
    $buildHeaders .= "Host:localhost\r\n";
    $buildHeaders .= "Authorization: Basic " . $authPass . "\r\n";
    $buildHeaders .= "\r\n";
    
    fputs($openSocket, $buildHeaders);
    while(!feof($openSocket)) {
    fgets($openSocket,128);
    }
    fclose($openSocket);
     
    echo $newDomain = "http://" . $subDomain . "." . $rootDomain . "/";
?>
于 2021-08-25T07:49:21.387 回答
0

你确定它可能去http://vikku.info/programming/php/create-subdomain-dynamically-in-php-code-to-create-subdomains-in-server-using-php.htmhttp:// www.phpclasses.org/browse/file/17134.html

只需配置添加子域名,cpanel用户名,cpanel密码,domail名称等设置。它会起作用。

例如

如果您的子域名是 test.example.com

create_subdomain("test","CPANEL_USERNAME","CPANEL_PASSWORD","example.com");

于 2014-06-13T05:37:33.360 回答