Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ruby-on-rails-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在PHP中通过用户表单自动创建子域_Php_Forms_Subdomain_Cpanel - Fatal编程技术网

在PHP中通过用户表单自动创建子域

在PHP中通过用户表单自动创建子域,php,forms,subdomain,cpanel,Php,Forms,Subdomain,Cpanel,我在这里创建了这个表单,它将接受用户的输入,并在CPANEL上创建具有该名称的子域。它不返回任何错误,但也不创建子域。这是表格 <!DOCTYPE html> <html> <head> <title></title> </head> <body> <form action="domaingen.php" method="post"> <input type="t

我在这里创建了这个表单,它将接受用户的输入,并在CPANEL上创建具有该名称的子域。它不返回任何错误,但也不创建子域。这是表格

<!DOCTYPE html>
<html>
<head>
    <title></title>
</head>
<body>
    <form action="domaingen.php" method="post">
        <input type="text" name="userInput">
        <input type="submit" name="">
    </form>
</body>

这里是domaingen.php

<?php

// Set the name for your New Sub Domain    
$subDomainname = $_POST['userInput'];

// cPanel Username
$cPanelUserName = "XXXXXXXX";

// cPanel Password    
$cPanelPassName = "XXXXXXXXXX";

// Main Domain Name
$rootDomainName = "XXXXXXXXXXX";

// Function to create subdomain
function create_subdomain($subDomain, $cPanelUser, $cPanelPass, $rootDomain) {

    // Generate URL for access the subdomain creation in cPanel through PHP
    $buildRequest = "/frontend/x3/subdomain/doadddomain.html?rootdomain=" . $rootDomain . "&domain=" . $subDomain . "&dir=public_html/subdomains/" . $subDomain;

    // Open the socket
    $openSocket = fsockopen('localhost', 2082);
    if (!$openSocket) {
        // SHow error
        return "Socket error";
        exit();
    }

    // Login Details
    $authString = $cPanelUser . ":" . $cPanelPass;

    // Encrypt the Login Details
    $authPass = base64_encode($authString);

    // Request to Server using GET method
    $buildHeaders = "GET " . $buildRequest . "\r\n";

    // HTTP
    $buildHeaders.= "HTTP/1.0\r\n";

    // Define Host
    $buildHeaders.= "Host:localhost\r\n";

    // Request Authorization
    $buildHeaders.= "Authorization: Basic " . $authPass . "\r\n";
    $buildHeaders.= "\r\n";

    // fputs
    fputs($openSocket, $buildHeaders);
    while (!feof($openSocket)) {
        fgets($openSocket, 128);
    }

    fclose($openSocket);

    // Return the New SUbdomain with full URL
    $newDomain = "http://" . $subDomain . "." . $rootDomain . "/";

    // return with Message
}

// Call the subdomain creator function
echo create_subdomain($subDomainname, $cPanelUserName, $cPanelPassName, $rootDomainName);
?>


您所说的“创建子域”是什么意思?看起来你只是想提出一个简单的请求。你到底想做什么?我想根据用户的请求创建一个新的子域,用户通过表单发送一个名称,然后下一个文件生成一个子域。