Page 3 of 4 FirstFirst 1234 LastLast
Results 31 to 45 of 55

Thread: create account cpanel - php

  1. #31
    Member
    Join Date
    Dec 2010
    Posts
    35

    Default Re: create account cpanel - php

    I am leaving this link, in case anyone comes back to this thread in 2018, and wants to know how to create a WHM account in PHP:

    /http://www.sitepoint.com/forums/showthread.php?823468-Please-Help-Me!-I-can-t-create-cPanel-accounts-with-PHP

  2. #32
    cPanel Product Evangelist Infopro's Avatar
    Join Date
    May 2003
    Location
    Pennsylvania
    Posts
    10,122
    cPanel/WHM Access Level

    Root Administrator

    Default Re: create account cpanel - php

    There is {{{NO functional script on the Internet of planet Earth (in this dimension) that allows automatic creation of WHM accounts with cPanel 11.30.5}}} - PERIOD.
    Sure there is, widely used: WHMCS - The Complete Client Management, Billing & Support Solution

  3. #33
    Member
    Join Date
    Dec 2010
    Posts
    35

    Default Re: create account cpanel - php

    Quote Originally Posted by Infopro View Post
    That's not a script, it's a complete software.

    I mean a PHP script that when called in a browser will create a WHM account.

  4. #34
    Technical Product Specialist cPanelDavidG's Avatar
    Join Date
    Nov 2006
    Location
    Houston, TX
    Posts
    11,307
    cPanel/WHM Access Level

    Root Administrator

    Default Re: create account cpanel - php

    Quote Originally Posted by MrLeN View Post
    Code:
    $ip = getenv('localhost');
    $root_pass = getenv('fordtires');
    getenv() is a function that gets an environmental variable at runtime. Like any PHP function, as you likely already know, you can learn more about it by typing php.net/FUNCTIONNAME (replacing FUNCTIONNAME with the name of the function) into your web browser - for example: php.net/getenv brings you to PHP: getenv - Manual

    Since there's no such environmental variable as localhost, I assume you are attempting to set the IP address to localhost. Based on our prior exchanges of your expertise with the PHP language, you probably already know this is how you do that:

    Code:
    $ip = 'localhost';
    IIRC, there's no environmental variable named fordtires either, so you may want to adjust that assignment as well.

  5. #35
    Technical Product Specialist cPanelDavidG's Avatar
    Join Date
    Nov 2006
    Location
    Houston, TX
    Posts
    11,307
    cPanel/WHM Access Level

    Root Administrator

    Default Re: create account cpanel - php

    Quote Originally Posted by MrLeN View Post
    Well, I changed line 133 to:

    Code:
    	// The host to connect to
    	private $host				=	'localhost';
    ..and then my previous error went away.

    But now I have a new error:

    Code:
    Warning: Unterminated comment starting line 1796 in /home/banana/public_html/inc/xmlapi.php on line 1796
    
    Parse error: syntax error, unexpected $end, expecting T_FUNCTION in /home/banana/public_html/inc/xmlapi.php on line 1796
    I concur with above advise, start fresh with new copies of the scripts - I know myself when I do late night coding sessions that I sometimes start forgetting commas and semicolons which mess things up.

    If you still receive errors like this, attach the code files to your forum post so we can assist.

  6. #36
    Member
    Join Date
    Dec 2010
    Posts
    35

    Default Re: create account cpanel - php

    So, I was right in the first place? I shouldn't have been changing the xmlapi file?

  7. #37
    Technical Product Specialist cPanelDavidG's Avatar
    Join Date
    Nov 2006
    Location
    Houston, TX
    Posts
    11,307
    cPanel/WHM Access Level

    Root Administrator

    Default Re: create account cpanel - php

    Quote Originally Posted by MrLeN View Post
    So, I was right in the first place? I shouldn't have been changing the xmlapi file?
    Actually you need to modify the variables near the top of the xmlapi file. This is what allows that class to connect to the server. The rest of the files you see on GitHub are just calling functions from that class just to demonstrate some things you can do with that class. However, everything governing connection to the server, how to connect (password vs. key) etc. is stored in those variables near the top of the xmlapi file.

  8. #38
    Integration Developer cPanelDavidN's Avatar
    Join Date
    Dec 2009
    Location
    Houston, TX
    Posts
    570

    Default Re: create account cpanel - php

    MrLeN,

    The xmlapi.php file is a PHP class make for inclusion in your script. There is no need to alter it. The class has methods for defined the values necessary to make a successful call. The values that are defined at the beginning of the class only defaults and SHOULD NOT BE ALTERED!

    The example script found on GitHub does work; you need to set the $ip, $root_pass, and the $acct variables according to your situation. The $acct associative array will, of course, need to be populated dynamically based on input from the visitor (or however you website signup works). The $ip variable is the server address, you can assign in the string 'localhost'...no need to use the getenv() function. The same is true of the $root_pass variable.

    So, you should like have a script similar to this:

    PHP Code:
    <?php
    /*
     * =====SETUP =====
     */

    // Import the xmlapi client class
    //  - reference where you have the xmlapi.php class on you server
    include_once "../xmlapi.php";

    // Define the variables necessary for the class object to connect and
    //  authenticate with the cPanel & WHM server
    $ip 'localhost';
    $root_pass 'fordtires';

    // Instantiate the PHP object from the xmlapi class
    //  - At minimum, it requires that a server address is provided at instantiation
    $xmlapi = new xmlapi($ip);

    // Tell the object how you want to authenticate
    //  - The password_auth() function is used for user/password authentication
    //  - Alternatively, you can use hash_auth() if you have the remote access hash key
    $xmlapi->password_auth("root",$root_pass);

    // For testing, turn on debugging
    // - there's a couple of long threads in the forum about how your PHP error reporting
    //   settings can affect the presentation of the generated output
    $xmlapi->set_debug(1);


    /*
     * ===== MAIN WORK =====
     */

    // Prepare dynamic data
    $acct = array(
     
    'username' => $new_user_to_create,
     
    'password' => $password_for_new_user,
     
    'domain'   => $domain_owned_by_new_user
    );

    // Make the new account using the object's createacct() method
    $result $xmlapi->createacct($acct);

    /*
     * ===== OTHER WORK =====
     */

    //...do error checking of the result, render a success/fail response to the browser, etc...
    Regards,
    -DavidN
    David Neimeyer
    Integration Developer

    sdk.cpanel.net
    APIs: XML-API API1 & API2
    Check Out: Developer Downloads Integration Blog
    Need Support? Support Ticket Developer Forum Feature Requests

  9. #39
    cPanel Product Evangelist Infopro's Avatar
    Join Date
    May 2003
    Location
    Pennsylvania
    Posts
    10,122
    cPanel/WHM Access Level

    Root Administrator

    Default Re: create account cpanel - php

    SHOULD NOT BE ALTERED!
    I apologize for steering this thread in the wrong direction.

  10. #40
    Member
    Join Date
    Dec 2010
    Posts
    35

    Default Re: create account cpanel - php

    Quote Originally Posted by cPanelDavidN View Post
    MrLeN,

    The xmlapi.php file is a PHP class make for inclusion in your script. There is no need to alter it. The class has methods for defined the values necessary to make a successful call. The values that are defined at the beginning of the class only defaults and SHOULD NOT BE ALTERED!

    The example script found on GitHub does work; you need to set the $ip, $root_pass, and the $acct variables according to your situation. The $acct associative array will, of course, need to be populated dynamically based on input from the visitor (or however you website signup works). The $ip variable is the server address, you can assign in the string 'localhost'...no need to use the getenv() function. The same is true of the $root_pass variable.

    So, you should like have a script similar to this:

    PHP Code:
    <?php
    /*
     * =====SETUP =====
     */

    // Import the xmlapi client class
    //  - reference where you have the xmlapi.php class on you server
    include_once "../xmlapi.php";

    // Define the variables necessary for the class object to connect and
    //  authenticate with the cPanel & WHM server
    $ip 'localhost';
    $root_pass 'fordtires';

    // Instantiate the PHP object from the xmlapi class
    //  - At minimum, it requires that a server address is provided at instantiation
    $xmlapi = new xmlapi($ip);

    // Tell the object how you want to authenticate
    //  - The password_auth() function is used for user/password authentication
    //  - Alternatively, you can use hash_auth() if you have the remote access hash key
    $xmlapi->password_auth("root",$root_pass);

    // For testing, turn on debugging
    // - there's a couple of long threads in the forum about how your PHP error reporting
    //   settings can affect the presentation of the generated output
    $xmlapi->set_debug(1);


    /*
     * ===== MAIN WORK =====
     */

    // Prepare dynamic data
    $acct = array(
     
    'username' => $new_user_to_create,
     
    'password' => $password_for_new_user,
     
    'domain'   => $domain_owned_by_new_user
    );

    // Make the new account using the object's createacct() method
    $result $xmlapi->createacct($acct);

    /*
     * ===== OTHER WORK =====
     */

    //...do error checking of the result, render a success/fail response to the browser, etc...
    Regards,
    -DavidN
    Ok, thank you. I will try again.

  11. #41
    Member
    Join Date
    Dec 2010
    Posts
    35

    Default Re: create account cpanel - php

    Just to be sure, I am pointing out that this is the file I am about to download:

    https://github.com/CpanelInc/xmlapi-...ter/xmlapi.php

  12. #42
    Member
    Join Date
    Dec 2010
    Posts
    35

    Default Re: create account cpanel - php

    YAY!

    *Falls off chair*

    It worked!

    Here's the code:

    Code:
    <?php
    
    /*
     * =====SETUP =====
     */
    
    // Import the xmlapi client class
    //  - reference where you have the xmlapi.php class on you server
    include_once "inc/xmlapi.php"; //yes I have it in the inc folder!
    
    // Define the variables necessary for the class object to connect and
    //  authenticate with the cPanel & WHM server
    $ip = 'localhost';
    $root_pass = 'fordtires';
    $new_user_to_create = "teasugar";
    $password_for_new_user = "5tag35sg35sdg";
    $domain_owned_by_new_user = "teasugar.banana.com";
    
    // Instantiate the PHP object from the xmlapi class
    //  - At minimum, it requires that a server address is provided at instantiation
    $xmlapi = new xmlapi($ip);
    
    // Tell the object how you want to authenticate
    //  - The password_auth() function is used for user/password authentication
    //  - Alternatively, you can use hash_auth() if you have the remote access hash key
    $xmlapi->password_auth("root",$root_pass);
    
    // For testing, turn on debugging
    // - there's a couple of long threads in the forum about how your PHP error reporting
    //   settings can affect the presentation of the generated output
    $xmlapi->set_debug(1);
    
    
    /*
     * ===== MAIN WORK =====
     */
    
    // Prepare dynamic data
    $acct = array(
     'username' => $new_user_to_create,
     'password' => $password_for_new_user,
     'domain'   => $domain_owned_by_new_user
    );
    
    // Make the new account using the object's createacct() method
    $result = $xmlapi->createacct($acct);
    
    /*
     * ===== OTHER WORK =====
     */
    
    //...do error checking of the result, render a success/fail response to the browser, etc... 
    echo "Ok, now I am gonna look in WHM to see if the account was created!";
    exit;
    I am E XTREMELY happy now!

    My website will be launched in a couple of hours now that I have this working.

    Thanks heaps cPanelDavidN

    Just one more question...

    ...how can I add a package?

  13. #43
    Member
    Join Date
    Dec 2010
    Posts
    35

    Default Re: create account cpanel - php

    Answer: It's not possible.

    *as I come to find out after trying to add the functionality all day*

    So, even though I have all this working now, I can't use it - because if I can't select a package, there's no point creating the account.

    So, I am back to square 1: Loooking for a functional script that allows me to create WHM accounts (and set the package in the process), via PHP.

    I have two courses of action at this point:

    1). See if I can find a script that will allow me to modify the package, and paste it into my script after the package has been created. But I think that will give me a bad case of deja vu. I am already suffering from PTSD from trying to find a script that allows me to create the account in the first place.

    2). I can let it set up the default account, and manually modify the package after people have made an order. However, this would be rather confusing for the customer if they see that they have unlimited space and transfer, and then it was taken away.

    Any help will be appreciated. I am not far away from curling up into a corner of my house and crying myself to sleep, while rocking backwards and forwards.

  14. #44
    Integration Developer cPanelDavidN's Avatar
    Join Date
    Dec 2009
    Location
    Houston, TX
    Posts
    570

    Default Re: create account cpanel - php

    If you want to specify a package when using the createacct() function of the Remote Api (aka XML/JSON API), then you must pass the value in the 'plan' parameter.

    So, going from the previous example, make a change similar to this:
    PHP Code:
    // Prepare dynamic data
    $acct = array(
        
    'username' => $new_user_to_create,
        
    'password' => $password_for_new_user,
        
    'domain'   => $domain_owned_by_new_user,
        
    'plan'     => $package_user_will_inherit_limits_from
    ); 
    Regards,
    -David

    P.S. The 'plan' parameter is different than the 'pkgname'. When 'savepkg' is set to '1', then the limits established for the new user will be used as a template for a new package; the value of 'pkgname' will be used as the name for the new package. I'm pretty certain in your case you do not need 'savepkg' or its friend 'pkgname', since you haven't mentioned package creation...just section (which is what 'plan' is for).
    David Neimeyer
    Integration Developer

    sdk.cpanel.net
    APIs: XML-API API1 & API2
    Check Out: Developer Downloads Integration Blog
    Need Support? Support Ticket Developer Forum Feature Requests

  15. #45
    Technical Product Specialist cPanelDavidG's Avatar
    Join Date
    Nov 2006
    Location
    Houston, TX
    Posts
    11,307
    cPanel/WHM Access Level

    Root Administrator

    Default Re: create account cpanel - php

    Just to clarify, you would replace the previous $acct = array( ... ); stuff in your previously functional script... with what DavidN recommends. If you can't get this working despite things working, please let us know.

Page 3 of 4 FirstFirst 1234 LastLast

Similar Threads

  1. Auto Create Account w/PHP
    By markfrompf in forum cPanel Developers
    Replies: 24
    Last Post: 01-26-2012, 08:39 AM
  2. How to create email account through PHP on CPanel
    By dmaulik142 in forum cPanel Developers
    Replies: 0
    Last Post: 06-05-2008, 01:31 AM
  3. Is there any way to create a new FTP account from PHP?
    By arkamax in forum cPanel & WHM Discussions
    Replies: 3
    Last Post: 06-15-2005, 06:07 AM
  4. wwwacct -- Create Account [php]
    By dotenetted in forum cPanel & WHM Discussions
    Replies: 4
    Last Post: 03-13-2005, 10:30 PM
  5. [PHP] Create Account
    By dotenetted in forum cPanel & WHM Discussions
    Replies: 0
    Last Post: 02-03-2005, 11:23 AM