Community Forums
Connect with us on LinkedIn
+ Reply to Thread
Results 1 to 11 of 11
  1. #1
    Member
    Join Date
    May 2004
    Posts
    24

    Default Subdomain Script

    Hey,

    Guys i want to run a free small community short URL service, for this i need a php, curl whatevre type script to automaticaly add subdomains via cpanel and then set the forwarder to go to the website requested. I have looked around but seems most samples dont work or i cant get them to work. I am the owner of my own server so i can install more scripts if needed to make this work.

    Regards,
    Michio

  2. #2
    Member
    Join Date
    Aug 2003
    Posts
    15

    Default

    up up up
    i need too

  3. #3
    Member
    Join Date
    May 2004
    Posts
    24

    Default

    lol i guess that makes 2 of us waiting

  4. #4
    Member
    Join Date
    Feb 2004
    Posts
    7

    Default

    Use Wildcard DNS combined with php scripting. That removes the need for subdomains to be created using cPanel.

  5. #5
    Member
    Join Date
    Jul 2004
    Posts
    12

    Default

    Would there possibly be a sample or a website i could view to learn how do do this dns operation?

  6. #6
    Member
    Join Date
    Mar 2003
    Posts
    604

    Default

    Quote Originally Posted by xMichio
    Hey,

    Guys i want to run a free small community short URL service, for this i need a php, curl whatevre type script to automaticaly add subdomains via cpanel and then set the forwarder to go to the website requested. I have looked around but seems most samples dont work or i cant get them to work. I am the owner of my own server so i can install more scripts if needed to make this work.

    Regards,
    Michio
    Here is the code that I use to add sudmains through php:

    PHP Code:
    <?

    include ('../cpinfo.php');
    $authstr "$username:$password";
    $pass base64_encode($authstr);

    //Here we open a socket to the cpanel

    $socket2 fsockopen("www.mydomain.com",2082);
    if(!
    $socket2)
    {
    print(
    'Socket error');
    echo 
    "<BR>There was an error while setting up the account.  Please let support@mydomain.com know the above error";
    exit();
    }


    //Next, we add a subdomain with $ustring

    $indom "GET /frontend/xlagoon/subdomain/doadddomain.html?domain=$web_username&rootdomain=mydomain.com\r\n HTTP/1.0\r\nHost:$udomain\r\nAuthorization: Basic $pass\r\n\r\n";


    fputs($socket2,$indom);
    while (!
    feof($socket2)) {
            
    fgets ($socket2,128);
            }
    fclose($socket2);



    ?>
    And of course cpinfo.php contains my cpanel username and password, which is located above my public_html directory for security.

    With this particular code it just gives you a blank screen...at the end you could just add a forwarder to the page you want.

  7. #7
    Member
    Join Date
    Jun 2004
    Location
    Canada
    Posts
    378

    Default

    where are you submitting the subdomain name, pass and foldername?

    like what varriables would be assign etc? im lost there.
    Sheldon King
    Server Adminisrator
    http://www.forgehosting.com

  8. #8
    Member
    Join Date
    Mar 2003
    Posts
    604

    Default

    Quote Originally Posted by Sheldon
    where are you submitting the subdomain name, pass and foldername?

    like what varriables would be assign etc? im lost there.

    For the username and password I have a file called "cpinfo.php" that is stored above my public_html directory. Then I included that file and use the variables from it. This is for security reasons. The "cpinfo.php" file would just be this:

    [php]
    <?
    $udomain = "mydomain.com";
    $pass = "mypassword";
    ?>

    I appologize about the subdomain variable part. I forgot that on my particular script I have stored the subdomain as a session variable that I collected early on in a form.

    You would need this:

    PHP Code:
    $subdomain "mysubdomainName" 

    or if you are getting that info from a form:
    $subdomain $_POST[field_name];

    and 
    change this line to match:

    $indom "GET /frontend/xlagoon/subdomain/doadddomain.html?domain=$subdomain&rootdomain=mydomain.com\r\n HTTP/1.0\r\nHost:$udomain\r\nAuthorization: Basic $pass\r\n\r\n"

  9. #9
    Member
    Join Date
    Mar 2003
    Posts
    604

    Default

    Quote Originally Posted by Sheldon
    where are you submitting the subdomain name, pass and foldername?

    like what varriables would be assign etc? im lost there.
    Ok, just in case the last post was confusing. Here would be the entire script with the variables defined up front:

    PHP Code:
    <?

    $uname 
    "cpanelusername";
    $password "mypassword";
    $subdomain "subdomainName";
    $udomain "yourdomain.com";

    $authstr "$username:$password";
    $pass base64_encode($authstr);


    //Here we open a socket to the cpanel

    $socket2 fsockopen("www.mydomain.com",2082);
    if(!
    $socket2)
    {
    print(
    'Socket error');
    echo 
    "<BR>There was an error while setting up the account.  Please let support@mydomain.com know the above error";
    exit();
    }


    //Next, we add a subdomain with $subdomain

    $indom "GET /frontend/xlagoon/subdomain/doadddomain.html?domain=$subdomain&rootdomain=mydomain.com\r\n HTTP/1.0\r\nHost:$udomain\r\nAuthorization: Basic $pass\r\n\r\n";


    fputs($socket2,$indom);
    while (!
    feof($socket2)) {
            
    fgets ($socket2,128);
            }
    fclose($socket2);



    ?>
    Yea, I think that covers it....sorry for the confusion.

  10. #10
    Member
    Join Date
    Jul 2004
    Posts
    12

    Default

    Helllo,

    I ran thelast script you provided and it didnt work. I had a mess around with it later trying to make it work and found that when we send the the line to add the subdomain [at the same time auth]it dosent auth right. The user/pass are correct ive checed. Any ideas?

  11. #11
    Registered User
    Join Date
    Aug 2004
    Posts
    1

    Default

    u change "mydomain.com" in rootdomain= directive? u must put your own domain mate..

Similar Threads & Tags
Similar threads

  1. Subdomain Creation Script
    By fast963 in forum cPanel and WHM Discussions
    Replies: 0
    Last Post: 05-23-2007, 04:20 PM
  2. Create SUBDOMAIN via PHP script
    By mlotfi63 in forum New User Questions
    Replies: 0
    Last Post: 12-28-2006, 11:28 PM
  3. Automatic Subdomain script
    By VMax in forum cPanel and WHM Discussions
    Replies: 8
    Last Post: 12-14-2004, 06:41 PM
  4. Create subdomain with a php script
    By mahdionline in forum cPanel and WHM Discussions
    Replies: 1
    Last Post: 03-02-2004, 11:45 PM
Linkedin       Facebook       Twitter       RSS       Flickr       YouTube