Create Sub Domains Using PHP
<!DOCTYPE><html><head><meta charset="utf-8" /><title>How to create dynamic subdomain in PHP</title> <meta content="earn how to create sub domain dynamically according user details in PHP. Tutorial to create sub domain in PHP." name="description" /><meta name="google-site-verification" content="liGddaK7I8_x0tSdKv36CRi_rMfRt3yMNjILkbOAxxY" /><link ref='http://feeds2.feedburner.com/webinfopedia' rel='alternate' title='Webinfopedia-Learn SEO, Web Designing and Web development easily with example and demos' type='application/rss+xml'/><meta name="msvalidate.01" content="CBFD6FA96646CD69CE09C869B2F6313" /><META name="y_key" content="2e447c925218040f" /><link rel="search" type="pplication/opensearchdescription+xml" href="http://www.webinfopedia.com/classes/opensearch.xml" title="SEO,PHP and Ajax blog" /> <meta content="create subdomain,create subdomain PHP, PHP create subdomain, Dynamic Subdomain, create HP subdomain, subdomain create script, Script to crate subdmain, how to subdomain" name="keywords" /><link rel="tylesheet" type="text/css" href="css/fb-notfication.css" media="screen" /><meta name="author" content="webinfopedia" /<meta name="copyright" content="webinfopedia.com" /><meta name="Robots" content="index, follow" /><meta name="language" content="English" /><link rel="icon" type="image/x-icon" href="http://www.webinfopedia.com/favicon.ico" /><script type="text/javascript"> (function() { var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true; po.src = 'https://apis.google.com/js/plusone.js'; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s); })();</script></head>
<body>
<?php
$sub=$_POST['sub'];
//Set the name for your New Sub Domain
$subDomainname="$sub";
//cPanel Username
$cPanelUserName="XXX";
//cPanel Password
$cPanelPassName="XXX";
//Main Domain Name
$rootDomainName="XXX";
//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
return "Created subdomain $newDomain";
}
//Call the subdomain creator function
echo create_subdomain($subDomainname,$cPanelUserName,$cPanelPassName,$rootDomainName);
?>
<form name="subdomain" action="" method="post">
Your Domain Name:<input type="text" name="sub" value="" required>
<input type="submit" name="submit" value="Create">
</form>
</body>
</html>
Note: Replace XXX with your control panel login details.

0 comments:
Post a Comment