Nov 22, 2009

Auto Creation Of Subdomain

free web hosting
Open Discussion > MODERATED AREA > Computers > Programming Languages > PHP Programming

Auto Creation Of Subdomain

liod
Hi, can anyone teach me how to make autocreation of subdomain like blogspot.com or http://cmblog.mobi. I`m clueless about making this.
Thank you and please help me.

Comment/Reply (w/o sign-up)

Quatrux
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 biggrin.gif

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 tongue.gif

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:

CODE
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
=============================

<?php

ini_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 us
echo "$errstr ($errno)n";

}else{

//send the server request

fputs($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 it
fclose($fp);
}

 

 

 


Comment/Reply (w/o sign-up)

triplebtalk
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... mellow.gif

Comment/Reply (w/o sign-up)

Nabb
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 ?> tongue.gif

Comment/Reply (w/o sign-up)

triplebtalk
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...

Comment/Reply (w/o sign-up)

moonless
QUOTE (triplebtalk @ Dec 30 2008, 04:20 PM) *
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

Comment/Reply (w/o sign-up)

triplebtalk
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.

Comment/Reply (w/o sign-up)

sakmac
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 www.example.com is received, two look-up operations are performed on the master or slave server. The first finds 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.

Comment/Reply (w/o sign-up)



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

This textarea will convert to Rich-Text automatically (IE, Firefox, Chrome)

Similar Topics

Keywords :

  1. Delete Problem With Id
    Id as auto_increment, and identifier for a row (4)
  2. Auto Pruning An Sql Database With Php
    How can i do this? (5)
    Hey all. Now i have a DB, an SQL DB, and i need to auto prune the data there to delete rows lder
    than a certain time, lets say 2 months for now, the question is how do i do this? The obvious thing
    is just to add a field which is the numerical representation of the month when the data is entered
    and every time the DB is accessed it will check this number against the current month,in a numerical
    format, and if the difference is two or greater that row is deleted, so if the month is January, it
    would be O1 and if the current month is march then it would be O3 and the diff....
  3. Requesting Auto Generating Id Tag In Php Code
    Php Coding (3)
    Hello...I'm designing a website in PHP where ppl can submit their links for "cool sites".
    Anyway, when somebody submit's a link to a website for example "http://www.google.com" it
    creates an id such as "index.php?id=1134411593". I dont want the links to be converted into
    id's. I want it to remain as "http://www.google.com". I have the following coding on
    ( echo " ). I'm a novice. Please Help!!!! Thanks... Plus I
    also want to add the date on when the link was submitted. Please follow our forum rule by making....
  4. Suppressing Mysql Error In Php
    How to suppress auto generated mysql err (4)
    I am testing my website on my local machine. It is still in development stage and I am using
    php/mysql. If there is a mysql connection error, I am checking for the connection variable and
    displaying a proper error message. But even before it displays my error message, it displays an
    error message on browser thrown by mysql (MySQL Connection Failed: Access denied for user). Can I
    suppress this message and display only my message?....
  5. Can Reset The Id Auto Increment?
    phpMyadmin (15)
    hi, Can we reset the id auto increment in the mysql database using by phpMyadmin? let's say the
    shoutbox . the id #number table.. somehow i deleted some rows.. and i wanted to re-order/reset the
    id number acendingly in order rather than skip out.. thks ....
  6. About Set Permisstions....
    auto set it, how? (4)
    I have some problem about set permissions by automatic.. for example... I created txt file with
    php... but when my file was added to server(trap17), it always set to 644 and i want to set it to
    666 . Anybody help me... PLEASE /biggrin.gif" style="vertical-align:middle" emoid=":D" border="0"
    alt="biggrin.gif" />....

    1. Looking for Auto, Creation, Of, Subdomain

Searching Video's for Auto, Creation, Of, Subdomain
See Also,
advertisement


Auto Creation Of Subdomain

Affordable Web Hosting, Low cost Web Hosting - ComputingHost.com