MrLeN

Active Member
Dec 12, 2010
38
0
56
Ok, I changed it to this and ran it again:

Code:
$ip = getenv('localhost');
$root_pass = getenv('fordtires');
I got this error:

Fatal error: Uncaught exception 'Exception' with message 'No host defined' in /home/banana/public_html/inc/xmlapi.php:233 Stack trace: #0 /home/banana/public_html/create.php(28): xmlapi->__construct(false) #1 {main} thrown in /home/banana/public_html/inc/xmlapi.php on line 233
 

MrLeN

Active Member
Dec 12, 2010
38
0
56
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
 

MrLeN

Active Member
Dec 12, 2010
38
0
56
I have just spent a whole week working on a script.

I have everything ready to go, and I can't wait to launch my website.

This is the ONLY part I can't get working yet.

How long as cPanel been around? over 10 years?

There should be 53,000,000 pages on the Internet with info on how to make php create an account.

But instead, there's old scripts from 2008 which don't work anymore. There's 52 million unanswered threads all over the place, with people asking how to make the old script work. There's no new scrips anywhere (or I can't find them), and the one that I get directed to here doesn't work. And if I point that out I get told I should go lean what variables are.

I am starting to get upset :(

All I want to do is create a new account in cPanel with PHP. One would think it would not be hard to find such a script considering the age and popularity of cPanel.

I feel like I am in the twilight zone.

I tell you something. When I DO get something that works, I am going to create a website DEDICATED to it, so no other poor person has to go through what I have to go through :(
 

Infopro

Well-Known Member
May 20, 2003
17,112
514
613
Pennsylvania
cPanel Access Level
Root Administrator
Twitter
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
Well, you might want to start over with fresh scripts unedited to be sure you've got those variables setup correctly.

I'm not sure of the interest in creating accounts via PHP, but I would think that if these scripts did not work, the Gentlemen that created them would have updated them between July last year and today.

No one here has told you to go learn variables. You do need to know where the correct variables are and edit them correctly though.

Getting mad doesn't help there, or here.
 

MrLeN

Active Member
Dec 12, 2010
38
0
56
I give up.

I am going to change my script so that it sends the customer an email, telling them to wait 24 hours, and I'll create the accounts manually. Sucks, but what can I do?

I'll do that for the time being. I have been working on this for two days,a nd I have tried absolutely everything humanly imaginable.

There's no working script that allows automatic creation via PHP.

Not one that still works anyway.

And I am not being smart.

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.

Plain and simple.

If anyone wants to prove me wrong - go ahead.

Thanks to everyone who tried to help me.
 

MrLeN

Active Member
Dec 12, 2010
38
0
56
..and for what it's worth:

/http://www.zubrag.com/scripts/create-cpanel-whm-account.php

This USED to work. I was using it with another website.

But it doesn't work anymore.

Something changed.

*and no, whoever wrote it hasn't fixed it, or revised it. It's the same version I downloaded a year ago (or more). I compared the code.
 

MrLeN

Active Member
Dec 12, 2010
38
0
56
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
 

cPanelDavidG

Technical Product Specialist
Nov 29, 2006
11,216
13
313
Houston, TX
cPanel Access Level
Root Administrator
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.
 

cPanelDavidG

Technical Product Specialist
Nov 29, 2006
11,216
13
313
Houston, TX
cPanel Access Level
Root Administrator
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.
 

cPanelDavidG

Technical Product Specialist
Nov 29, 2006
11,216
13
313
Houston, TX
cPanel Access Level
Root Administrator
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.
 

cPanelDavidN

Well-Known Member
Staff member
Dec 17, 2009
571
3
68
Houston, TX
cPanel Access Level
Root Administrator
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:
<?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
 

MrLeN

Active Member
Dec 12, 2010
38
0
56
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:
<?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.