0

I am trying to create subdomain dynamically using php. When user enters subdomain name in html form, a subdomain by that name should be created. I have got the script for that.

But when i run this, i get blank page, no directory is getting created. Somebody tell me where i am going wrong

php code is like this create.php

<?php
if(isset($_POST['subdomain_name']))
{

//$subDomain = $_POST['subdomain_name'];
    function create_subdomain($subDomain,$cPanelUser,$cPanelPass,$rootDomain) {
 echo $rootDomain;
    $buildRequest = "/frontend/x3/subdomain/doadddomain.html?rootdomain=" . $rootDomain . "&domain=" . $subDomain . "&dir=public_html/subdomains/" . $subDomain;

    $openSocket = fsockopen('localhost',2082);
    if(!$openSocket) {
    echo "error";
        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);
    echo $openSocket;
    while(!feof($openSocket)) {
    echo $opensocket;
    fgets($openSocket,128);
    }
    fclose($openSocket);

    $newDomain = "http://" . $subDomain . "." . $rootDomain . "/";
 echo "new domain";
 echo $newDomain;
//  return "Created subdomain $newDomain";

}
    $cpaneluser = "username";
    $cpanelpass = "password";
    $cpanel_skin = "x3";
    $subd = $_POST['subdomain_name'];
    $request = "/frontend/$cpanel_skin/subdomain/doadddomain.html?rootdomain=$domain&domain=$subd";
    $result = create_subdomain($_POST['subdomain_name'],$cpaneluser,$cpanelpass,'ecommerce24.in');
    $show = strip_tags($result);
    if(strpos($show,"has been created!"))
    {
        echo "Subdomain Created!";
    }
}
?>

my html form

<form action="create.php" method="post">
          New Subdomain Name : <input name="subdomain_name" type="text" /><br />
          <input type="submit" name="submit" value="Submit" />
</form> 
hakre
  • 184,866
  • 48
  • 414
  • 792
user1321271
  • 255
  • 3
  • 10
  • 21
  • 1
    *"It doesn't work"* [doesn't explain the problem](http://stuck.include-once.org/#help3) enough. You need to elaborate on your input, expected and actual outcomes, or concretise error messages. Also please check your wording, it looks a bit quickly typed and it's also nice to see if askers are properly indenting their code as it has been placed to be read by others. – hakre Sep 29 '12 at 14:14
  • 3
    Looks like > http://vikku.info/programming/php/create-subdomain-dynamically-in-php-code-to-create-subdomains-in-server-using-php.htm ? Why don't you ask the owner of this code what the problem is? – Glavić Sep 29 '12 at 14:16
  • The first step here is to turn on error logging so you know what's going on. – jli Sep 29 '12 at 14:16
  • @glavić: Good point, I mean SO is not offering support for third-party code. – hakre Sep 29 '12 at 14:17
  • Oh, snap! Good catch! +1 – L0j1k Sep 29 '12 at 14:18
  • Duplicate by same user? [creating subdomain dynamically](http://stackoverflow.com/questions/10926406/creating-subdomain-dynamically?) - obviously the same topic and probably the same action. Please edit your previous question instead if you have updates. – hakre Sep 29 '12 at 14:24
  • You are creating a bad situation using authentication information cleartext in the URL. – L0j1k Sep 29 '12 at 14:16

1 Answers1

1

Try putting this at the biginning of your script:

error_reporting (E_ALL | E_STRICT);
ini_set ('display_errors', '-1');

It might make php show you an error message which will lead to the solution.

Silver Light
  • 41,576
  • 32
  • 119
  • 161
  • 2
    I'd say this is the perfect comment in the sense like *This needs basic debugging first*. – hakre Sep 29 '12 at 14:21
  • @hakra, yes, I guess so. I just think, that, in this case, php will tell exactly what needs to be done to fix the issue :) – Silver Light Sep 29 '12 at 14:23
  • Yes, but if that is the cause of the question, I think it's better placed as a comment. I normally have this one: This calls for basic debugging first - which code is hit when the screen is blank? Please do a `error_reporting(~0); ini_set('display_errors', 1);` at the very beginning of your script. Additionally you should [enable error logging](http://www.cyberciti.biz/tips/php-howto-turn-on-error-log-file.html) and follow the error log. ;; also see https://gist.github.com/2768567 and http://stuck.include-once.org/ :) – hakre Sep 29 '12 at 14:26