如何让我的用户拥有自定义域名?

时间:2012-07-12 20:05:17

标签: php .htaccess

我想创建一个允许我的用户拥有自定义域的功能。就像blogger / wordpress正在做的那样。

e.g。

http://www.domain.com

用户可以拥有自己的自定义域

http://www.custom.com

在www.custom.com中键入地图到www.domain.com

我该怎么做?我正在使用PHP。这是服务器配置吗?

3 个答案:

答案 0 :(得分:1)

您需要更改新网站的DNS以转发到他们的网站。

答案 1 :(得分:1)

我使用我的多帐户平台执行此操作。我使用cpanel api在每次指定域名时创建一个附加域,并要求他们将域名中的名称服务器更改为我的主机。 所以这是一个例子: www.example.com 要求用户将名称服务器更改为ns1.hostingwerks.com和ns2.hostingwerks.com 提示用户输入他们的域名 使用api添加他们的域名 告诉用户它已经完成但是需要一些时间来提升它 这要求你有权访问,但它可能会给你一些帮助。

if(!empty($domain) AND $olddomain != $domain){

    $d = explode(".",$origdomain);
    if(count($d) != 1){
    if($d[0] == "www" OR $d[0] == "http://www" OR $d[0] == "https://www"){
    $origdomain = $d[1] .".". $d[2];
    }
    else {
    $origdomain = $d[0] .".". $d[1];
    }
    }
    if(substr($origdomain, 0, 8) == "https://"){
    $origdomain = substr($origdomain, 8);
    }
    elseif(substr($origdomain, 0, 7) == "http://"){
    $origdomain = substr($origdomain, 7);
    }
    $dom = $origdomain;
    $user = "your cpanel client username";
    $addonpass = "your new domain's password";
    $cpanel_skin = "x3";
    $passw = "your cpanel password";
    $ownername = "your cpanel hosting user name";
    $pass = "your cpanel password";
    $host = "localhost";
    //Using 'explode' breaks the domain into its constituent pieces, the name and the extension (TLD), and puts them in an array
    $domai = explode('.',$dom);
    /*the directory path is defined by the first element appended to public_html.  It does not matter where this file, 'addonhelper.php', is located - 
    the program will always install the addon domains to this directory.  If this needs to be changed, this line needs to be updated.
    Some versions of Cpanel do not allow for this to be changed and will ignore changes.  Most notably - version X.*/
    $dir="public_html/sys";
    //the user is the first element of the $domain, as requested
    $user=trim($domai[0]);
    //put the domain back together and trim whitespace.
    $dom=trim($domai[0]).".".trim($domai[1]);
    //create the cpanel request.
    $request = "/frontend/$cpanel_skin/addon/doadddomain.html?domain=$dom&user=$user&dir=$dir&pass=$addonpass";
    //process the request with addondomain below
    $sock = @fsockopen($host,2082);
    if(!$sock) {
        print('Socket error');
        exit();
    }
    //authenticate the connection
    $authstr = "$ownername:$passw";
    //make the passphrase slightly more difficult to decipher
    $pass = base64_encode($authstr);
    $in = "GET $request\r\n";
    $in .= "HTTP/1.0\r\n";
    $in .= "Host:$host\r\n";
    $in .= "Authorization: Basic $pass\r\n";
    $in .= "\r\n";
    //process
    fputs($sock, $in);
    while (!feof($sock)) {
        $result .= fgets ($sock,128);
    }
    fclose( $sock );

答案 2 :(得分:0)

如果您只是想要更改单个域,请将其上的名称服务器更改为相同,并将其设置为plesk / cpanel中的添加到同一文件夹。或者您可以转发域并屏蔽它。这也有效。 http://support.godaddy.com/help/article/422/forwarding-or-masking-your-domain-name