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
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
Sure there is, widely used: WHMCS - The Complete Client Management, Billing & Support SolutionThere 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.
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:
IIRC, there's no environmental variable named fordtires either, so you may want to adjust that assignment as well.Code:$ip = 'localhost';
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.
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.
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:
Regards,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...
-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
I apologize for steering this thread in the wrong direction.SHOULD NOT BE ALTERED!![]()
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
YAY!
*Falls off chair*
It worked!
Here's the code:
I am E XTREMELY happy now!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;
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?
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.
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:
Regards,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
);
-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
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.