creating subdomain dynamically

2019-06-05 03:28发布

问题:

I am developing e-commerce platform to build their own site. In that, when customer logs in he will fill a form with his store name. When he submits he will get his space in the domain like this. storename.domain.com

I am not getting how to achieve this. please suggest

i have got this code but don't know how to modify it to take the subdomain name from the form control

function subd($host,$port,$ownername,$passw,$request) {

  //$sock = fsockopen('localhost',2082);
  $sock = fsockopen("www.mydomain.com", 80, $errno, $errstr, 30);
  echo $sock;

  if(!$sock) {
    print('Socket error');
    exit();
  }

  $authstr = "$ownername:$passw";
  $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";

  fputs($sock, $in);

  while (!feof($sock)) {
    $result .= fgets ($sock,128);
  }

  fclose( $sock );
  return $result;
}
$domain='mydomain.com';

$subd="f1f1f1f1";

$request = "/frontend/$cpanel_skin/subdomain/doadddomain.html?rootdomain=$domain&domain=$subd";