The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Subdomain Script

Discussion in 'General Discussion' started by xMichio, Jul 10, 2004.

  1. xMichio

    xMichio Member

    Joined:
    May 4, 2004
    Messages:
    24
    Likes Received:
    0
    Trophy Points:
    1
    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. }{iJacK

    }{iJacK Member

    Joined:
    Aug 21, 2003
    Messages:
    15
    Likes Received:
    0
    Trophy Points:
    1
    up up up
    i need too
     
  3. xMichio

    xMichio Member

    Joined:
    May 4, 2004
    Messages:
    24
    Likes Received:
    0
    Trophy Points:
    1
    lol i guess that makes 2 of us waiting :rolleyes:
     
  4. S2S-Robert

    S2S-Robert Member

    Joined:
    Feb 14, 2004
    Messages:
    7
    Likes Received:
    0
    Trophy Points:
    1
    Use Wildcard DNS combined with php scripting. That removes the need for subdomains to be created using cPanel.
     
  5. E9N_Michio

    E9N_Michio Member

    Joined:
    Jul 11, 2004
    Messages:
    12
    Likes Received:
    0
    Trophy Points:
    1
    Would there possibly be a sample or a website i could view to learn how do do this dns operation? :confused:
     
  6. noimad1

    noimad1 Well-Known Member

    Joined:
    Mar 27, 2003
    Messages:
    627
    Likes Received:
    0
    Trophy Points:
    16
    Here is the code that I use to add sudmains through php:

    PHP:
    <?

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

    Sheldon Well-Known Member

    Joined:
    Jun 7, 2004
    Messages:
    378
    Likes Received:
    0
    Trophy Points:
    16
    Location:
    Canada
    where are you submitting the subdomain name, pass and foldername?

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

    noimad1 Well-Known Member

    Joined:
    Mar 27, 2003
    Messages:
    627
    Likes Received:
    0
    Trophy Points:
    16

    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]
    $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. noimad1

    noimad1 Well-Known Member

    Joined:
    Mar 27, 2003
    Messages:
    627
    Likes Received:
    0
    Trophy Points:
    16
    Ok, just in case the last post was confusing. Here would be the entire script with the variables defined up front:

    PHP:
    <?

    $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. E9N_Michio

    E9N_Michio Member

    Joined:
    Jul 11, 2004
    Messages:
    12
    Likes Received:
    0
    Trophy Points:
    1
    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. Derick

    Derick Registered

    Joined:
    Aug 13, 2004
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    1
    u change "mydomain.com" in rootdomain= directive? u must put your own domain mate..
     
Loading...

Share This Page