liod 0 Report post Posted December 30, 2008 Hi, can anyone teach me how to make autocreation of subdomain like blogspot.com or http://forums.xisto.com/no_longer_exists/. I`m clueless about making this.Thank you and please help me. Share this post Link to post Share on other sites
Quatrux 4 Report post Posted December 30, 2008 (edited) I remember I once wanted to do so, we were writing a service for users and for a user we always wanted to create a subdomain as it's more reliable for search engines then example.com/user/service but I never found a way to do it as simply as it could be by just using PHP, as I remember you need to have permissions to use Apache httpd.conf or something like that and edit it..Another way is to fake a subdomain using mode rewrite to make anything.example.com work and anything could be written, but for that you need to edit httpd.conf even though I never understood how, maybe after 4 years there are more resources on google to find out Anyway, you would need more permissions to do that, if you're using a simple hosting, I doubt you could simply access httpd.conf and I don't know if it could be done by just using .htaccess as it also requires to do something with DNS after you create a directory.. You would need to have a server Just did a quick search and found another interesting method to do it using PHP, by connecting to CPanel if you're using it and making PHP create the subdomain through CPanel subdomains, of course I don't know if the script works, but it's really logical and I think you need to be careful to include it in your scripts, you need to write your CPanel username and password and the script will use those and make a request as if you would do it through CPanel!Here is the script: subdomainform.php<html><head><title>create a subdomain</title></head><body><form name="form1" method="post" action="addsubdomain.php"><h1>create Sub Domains</h1>Sub Domain Name : <input type="text" name="subdomain"><br /><input type="submit" name="Submit" value="Submit"></form></body></html> ==============================addsubdomain.php=============================<?phpini_set('display_errors', 1);$host = "domainname.com"; // your domain name without the www$port = 2082;$path = "/frontend/x/subdomain/doadddomain.html?domain=".$_POST['subdomain']."&rootdomain=".$host; //or .dll, etc. for authnet, etc.// these lines are changed$cpaneluser = "username";$cpanelpass = "pass";$authstr = "$cpaneluser:$cpanelpass";//****************************// Setup the Auth String$pass = base64_encode($authstr);$fp = fsockopen($host, $port, $errno, $errstr, $timeout = 30);if(!$fp){//error tell usecho "$errstr ($errno)n";}else{//send the server requestfputs($fp, "POST $path HTTP/1.1rn");fputs($fp, "Host: $hostrn");fputs($fp, "Authorization: Basic $pass rn");fputs($fp, "Content-type: application/x-www-form-urlencodedrn");fputs($fp, "Content-length: ".strlen($poststring)."rn");fputs($fp, "Connection: closernrn");fputs($fp, $poststring . "rnrn");//*************************************// Remove this to stop it from displaying the output fron the CPanel//*************************************//loop through the response from the server/*while(!feof($fp)) {echo fgets($fp, 4096);}*/while(!feof($fp)) { fgets($fp, 4096); }//close fp - we are done with itfclose($fp);} Edited December 30, 2008 by Quatrux (see edit history) Share this post Link to post Share on other sites
triplebtalk 0 Report post Posted December 30, 2008 That is a great script, isn't it a bit risky putting your cpanel username and password in there though? many people can easily access it and download it, then they have access to your account... Share this post Link to post Share on other sites
Nabb 0 Report post Posted December 30, 2008 PHP is executed on the server, not by the client. The user only sees what is outputted with echo, so only the response from adding the subdomain will be shown. I think the script is missing an ending ?> Share this post Link to post Share on other sites
triplebtalk 0 Report post Posted December 30, 2008 No, but the client can still download the PHP file... Do you see what am getting at, you would need to lock the folder the PHP is in so no one in the public can grab it out of your server space... Share this post Link to post Share on other sites
moonless 0 Report post Posted December 30, 2008 No, but the client can still download the PHP file... Do you see what am getting at, you would need to lock the folder the PHP is in so no one in the public can grab it out of your server space...Its impossible to unless you make it download from within the php file itself. A user cannot download the source code of a php file Share this post Link to post Share on other sites
triplebtalk 0 Report post Posted December 30, 2008 Yes you can, all you need to do is go to your download manager and paste in the address and there you go, you have the PHP file. Share this post Link to post Share on other sites
sakmac 0 Report post Posted December 30, 2008 Now what I would usually do is create a cname record that points to the necessary servers to do what you aim to do. CNAME RRs incur performance overheads. The most common DNS query is for an A RR, or an AAAA RR if IPv6 - the end system needs an address which is only defined with these RR types. In the above example if a query for the address of http://www.example.com/ is received, two look-up operations are performed on the master or slave server. The first finds http://www.example.com/ which finds a CNAME RR. This is followed by a query for server1.example.com to obtain the IP, that is, the CNAME chain is followed to attempt to resolve the request for an IP address. On low volume DNS servers the additional resources used are not significant but on high volume servers the additional load can become non-trivial. The user must make a choice to balance what many see as the convenience of using CNAME RRs against the possible performances degradation involved.CNAME RRs cannot have any other RRs with the same name, for example, a TXT - well that was true until DNSSEC came along and in this case RRSIG, NSEC and certain KEY RRs can now occupy the same name.While use of CNAME RRs with NS and MX records is widely implemented and generates a working configuration it is theoretically not permitted (RFC 1034 section 3.6.2) since it can result in lost names. The fragment below illustrates a widely used but technically invalid configuration. Share this post Link to post Share on other sites