So I am trying to automatically create subdomains for my website using PHP. I tried the following code but it gives me a 301 error and redirects me to my cPanel login
function createDomain($domain) {
// your cPanel username
$cpanel_user = 'User';
// your cPanel password
$cpanel_pass = 'Pass';
// your cPanel skin
$cpanel_skin = 'paper_lantern';
// your cPanel domain
$cpanel_host = 'example.com';
// subdomain name
$subdomain = $domain;
// directory - defaults to public_html/subdomain_name
$dir = 'public_html/user_site';
// create the subdomain
$sock = fsockopen($cpanel_host,2083);
if(!$sock) {
print('Socket error');
exit();
}
$pass = base64_encode("$cpanel_user:$cpanel_pass");
$in = "GET /frontend/$cpanel_skin/subdomain/doadddomain.html?rootdomain=$cpanel_host&domain=$subdomain&dir=$dir\r\n";
$in .= "HTTP/1.0\r\n";
$in .= "Host:$cpanel_host\r\n";
$in .= "Authorization: Basic $pass\r\n";
$in .= "\r\n";
fputs($sock, $in);
while (!feof($sock)) {
$result .= fgets ($sock,128);
}
fclose($sock);
return $result;
}
Like I said it gives me a 301 error and redirects to example.com:2083 instead of just doing it in the code and not having me login to the cPanel manually. Any help would be greatly appreciated!
ANSWER:
After fiddling with my code I realized that port 2082 and port 2083 are the same except that 2082 has no https:// so I changed the port to 2082 and it worked!
CODE:
function createDomain($domain) {
// your cPanel username
$cpanel_user = 'User';
// your cPanel password
$cpanel_pass = 'Pass';
// your cPanel skin
$cpanel_skin = 'paper_lantern';
// your cPanel domain
$cpanel_host = 'example.com';
// subdomain name
$subdomain = $domain;
// directory - defaults to public_html/subdomain_name
$dir = 'public_html/user_site';
// create the subdomain
$sock = fsockopen($cpanel_host,2082);
if(!$sock) {
print('Socket error');
exit();
}
$pass = base64_encode("$cpanel_user:$cpanel_pass");
$in = "GET /frontend/$cpanel_skin/subdomain/doadddomain.html?rootdomain=$cpanel_host&domain=$subdomain&dir=$dir\r\n";
$in .= "HTTP/1.0\r\n";
$in .= "Host:$cpanel_host\r\n";
$in .= "Authorization: Basic $pass\r\n";
$in .= "\r\n";
fputs($sock, $in);
while (!feof($sock)) {
$result .= fgets ($sock,128);
}
fclose($sock);
return $result;
}
API 1 is now dead. Also passing your cpanel password through a non-secure connection (ie port 2082 instead of 2083) is a very bad idea. Next thing you know someone will have hijacked your cpanel account!
However, combining the codes given here for authentication and here for adding a subdomain, gives us the following script which seems to work just fine:
<?php
$cpanelsername = "example";
$cpanelpassword = "**********";
$subdomain = 'newsubdomain';
$domain = 'example.com';
$directory = "/public_html/$subdomain"; // A valid directory path, relative to the user's home directory. Or you can use "/$subdomain" depending on how you want to structure your directory tree for all the subdomains.
$query = "https://$domain:2083/json-api/cpanel?cpanel_jsonapi_func=addsubdomain&cpanel_jsonapi_module=SubDomain&cpanel_jsonapi_version=2&domain=$subdomain&rootdomain=$domain&dir=$directory";
$curl = curl_init(); // Create Curl Object
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER,0); // Allow self-signed certs
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST,0); // Allow certs that do not match the hostname
curl_setopt($curl, CURLOPT_HEADER,0); // Do not include header in output
curl_setopt($curl, CURLOPT_RETURNTRANSFER,1); // Return contents of transfer on curl_exec
$header[0] = "Authorization: Basic " . base64_encode($whmusername.":".$whmpassword) . "\n\r";
curl_setopt($curl, CURLOPT_HTTPHEADER, $header); // set the username and password
curl_setopt($curl, CURLOPT_URL, $deletedir); // execute the query
$result = curl_exec($curl);
if ($result == false) {
error_log("curl_exec threw error \"" . curl_error($curl) . "\" for $query");
// log error if curl exec fails
}
curl_close($curl);
print $result;
?>
The result should be something like this:
{"cpanelresult":{"func":"addsubdomain","event":{"result":1},"apiversion":2,"module":"SubDomain","data":[{"reason":"The subdomain “newsubdomain.example.com” has been added.","result":1}],"preevent":{"result":1},"postevent":{"result":1}}}
To delete the subdomain, run this query through the above script:
$deletesub = "https://$domain:2083/json-api/cpanel?cpanel_jsonapi_func=delsubdomain&cpanel_jsonapi_module=SubDomain&cpanel_jsonapi_version=2&domain=".$subdomain.'.'.$domain."&dir=$directory"; //Note: To delete the subdomain of an addon domain, separate the subdomain with an underscore (_) instead of a dot (.). For example, use the following format: subdomain_addondomain.tld
And to delete the directory, run this:
$deletedir = "https://$domain:2083/json-api/cpanel?cpanel_jsonapi_module=Fileman&cpanel_jsonapi_func=fileop&op=unlink&sourcefiles=$directory";
Noel's answer from 2018 more than likely won't work anymore, but if you've come here looking for how to use the Cpanel API to add a subdomain, start at this link to see the arguments accepted for the Cpanel API Ver 2 for the SubDomain module addsubdomain.
Below is an example that worked perfectly well for me.
$whmusername = "cpanel_username";
$whmpassword = "cpanel_password";
$subdomain = 'newsubdomain';
$cpanel_ip = 'IP_ADDRESS'; //ip of cpanel or your_domain.com
$domain = "your_domain.com";
$query = "https://".$cpanel_ip."2083/json-api/cpanel?cpanel_jsonapi_module=SubDomain&cpanel_jsonapi_func=addsubdomain&cpanel_jsonapi_apiversion=2&dir=/public_html/".$subdomain.".".$domain."/&rootdomain=".$domain."&domain=".$subdomain."";
$curl = curl_init();
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER,0);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST,0);
curl_setopt($curl, CURLOPT_HEADER,0);
curl_setopt($curl, CURLOPT_RETURNTRANSFER,1);
$header[0] = "Authorization: Basic " . base64_encode($whmusername.":".$whmpassword) . "\n\r";
curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
curl_setopt($curl, CURLOPT_URL, $query);
$result = curl_exec($curl);
curl_close($curl);
Note that if you want to see what Cpanel is returning as a response for $result, then place print $result; after curl_close($curl);
Related
Currently, with PHP code, I'm creating MySQL databases in cPanel, then MySQL users, and then mapping them to the database, using these 4 PHP routines. The trouble is that every once in a blue moon, at a time when we think it's related to server load, this script says it's created the MySQL, user, and user->db mapping, but we can't see it in cPanel. When we go to MySQL command line, we see it there. And WordPress can't deploy to it -- says it can't reach the database. We have to go to command line MySQL to delete the database. When we manually run these routines under lower server load, the problem goes away. The problem is that I'm usually called back on the issue a day later than it actually occurred -- so I can't see what happened. And my logs just show me that WordPress couldn't deploy to the MySQL database. When I go looking, I don't see it in cPanel, but see it at command line in MySQL.
So, since these routines are problematic, I was wondering how Softaculous resolves this problem. Because even when my script fails, Softaculous still works just fine.
<?php
class cPanel {
public static function cp_curlData($sRootDomain, $sCpanelUser, $sCpanelPass, $sCpanelPort, $sPostData, $nTimeoutSeconds = 0) {
$sURL = ($sCpanelPort == 2083) ? 'https://' : 'http://';
$sURL .= $sRootDomain . ':' . $sCpanelPort . '/xml-api/cpanel';
$asHeader[0] = 'Authorization: Basic ' . base64_encode($sCpanelUser . ':' . $sCpanelPass) . "\r\n" .
"Content-Type: application/x-www-form-urlencoded\r\n" .
"Content-Length: " . strlen($sPostData) . "\r\n" . "\r\n" . $sPostData;
$hCurl = curl_init ();
curl_setopt($hCurl, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1');
curl_setopt($hCurl, CURLOPT_REFERER, 'https://www.google.com/?gws_rd=ssl#q=' . $sURL);
curl_setopt($hCurl, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($hCurl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($hCurl, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($hCurl, CURLOPT_URL, $sURL);
curl_setopt($hCurl, CURLOPT_HTTPHEADER, $asHeader);
curl_setopt($hCurl, CURLOPT_POST, 1);
if ($nTimeoutSeconds > 0) {
# curl_setopt($hCurl, CURLOPT_TIMEOUT, $nTimeoutSeconds);
# curl_setopt($hCurl, CURLOPT_CONNECTTIMEOUT, 30);
}
$s = curl_exec($hCurl);
return $s;
}
public static function cp_createDatabase($sRootDomain, $sCpanelUser, $sCpanelPass, $sCpanelPort, $sUnPrefixedDBName) {
global $gsCpanel_Last_Result;
$sPostData = 'user=' . $sCpanelUser . '&cpanel_xmlapi_module=Mysql&cpanel_xmlapi_func=adddb&cpanel_xmlapi_apiversion=1&arg-0=' . $sUnPrefixedDBName;
$nTimeoutSeconds = 60;
$s = self::cp_curlData($sRootDomain, $sCpanelUser, $sCpanelPass, $sCpanelPort, $sPostData, $nTimeoutSeconds);
$gsCpanel_Last_Result = "$s";
if (strpos($s, '<result>1</result>') > 0) {
$sDBName = $sCpanelUser . '_' . $sUnPrefixedDBName;
return $sDBName;
} else {
return FALSE;
}
}
public static function cp_createDBUser($sRootDomain, $sCpanelUser, $sCpanelPass, $sCpanelPort, $sUnPrefixedDBUser, $sDBPass) {
global $gsCpanel_Last_Result;
$sTest = $sCpanelUser . '_' . $sUnPrefixedDBUser;
if (strlen($sTest)>16) {
$sUnPrefixedDBUser = substr($sUnPrefixedDBUser, 0, (strlen($sUnPrefixedDBUser) - (strlen($sTest) - 16)));
}
$sPostData = 'user=' . $sCpanelUser . '&cpanel_xmlapi_module=Mysql&cpanel_xmlapi_func=adduser&cpanel_xmlapi_apiversion=1&arg-0=' . $sUnPrefixedDBUser . '&arg-1='. $sDBPass;
$s = self::cp_curlData($sRootDomain, $sCpanelUser, $sCpanelPass, $sCpanelPort, $sPostData);
$gsCpanel_Last_Result = "$s";
if (strpos($s, '<result>1</result>') > 0) {
$sDBUser = $sCpanelUser . '_' . $sUnPrefixedDBUser;
return $sDBUser;
} else {
return FALSE;
}
}
public static function cp_addUserToDatabase($sRootDomain, $sCpanelUser, $sCpanelPass, $sCpanelPort, $sUnPrefixedDBName, $sUnPrefixedDBUser) {
global $gsCpanel_Last_Result;
$sPostData = 'user=' . $sCpanelUser . '&cpanel_xmlapi_module=Mysql&cpanel_xmlapi_func=adduserdb&cpanel_xmlapi_apiversion=1&arg-0=' . $sUnPrefixedDBName . '&arg-1=' . $sUnPrefixedDBUser . '&arg-2=all';
$s = self::cp_curlData($sRootDomain, $sCpanelUser, $sCpanelPass, $sCpanelPort, $sPostData);
$gsCpanel_Last_Result = "$s";
return (strpos($s, '<result>1</result>') > 0);
}
} // end class
Softaculous has a glorious SDK that's free here:
http://www.softaculous.com/docs/File:Softaculous_Development_Kit.zip
Then, this code should help you install a blog using it. It's blazingly fast -- much faster than cPanel APIs.
<?php
// SOURCE: https://gist.github.com/mickaelandrieu/7271939
require_once('sdk.php');
$new = new Softaculous_API();
$new->login = 'https://user:password#domain.com:2083/frontend/x3/softaculous/index.live.php';
// Domain Name
$data['softdomain'] = 'root-or-addon-domain.com'; // OPTIONAL - By Default the primary domain will be used
// The directory is relative to your domain and should not exist. e.g. To install at http://mydomain/dir/ just type dir. To install only in http://mydomain/ leave this empty.
$data['softdirectory'] = ''; // OPTIONAL - By default it will be installed in the /public_html folder
// Admin Username
$data['admin_username'] = 'admin';
// Admin Pass
$data['admin_pass'] = 'pass';
// Admin Email
$data['admin_email'] = 'admin#domain.com';
// Database
$data['softdb'] = 'wp887'; // make something up that MySQL likes and won't cause a collision
//Database User Name
$data['dbusername'] = 'wp887'; // ditto
// DB User Pass
$data['dbuserpass'] = 'wp887'; // ditto
// Language
$data['language'] = 'en';
// Site Name
$data['site_name'] = 'Wordpess wp887';
// Site Description
$data['site_desc'] = 'WordPress API Test';
// Response
$res = $new->install(26, $data); // Will install WordPress(26 is its script ID)
// Unserialize
$res = unserialize($res);
// Done/Error
if(!empty($res['done'])){
echo 'Installed';
}else{
echo 'Installation Failed<br/>';
if(!empty($res['error'])){
print_r($res['error']);
}
}
SOURCE: https://gist.github.com/mickaelandrieu/7271939
I'm currently trying to get PHP to login and authenticate with a CAS single sign on server which is proving difficult.
The official site has some basic source code here which is supposed to handle the authentication and log in a user. As far as I can see and in my testing it completes steps 1 and 2 in the process (see this diagram for the basic process). Once I've logged into the test server I can complete step 3 and retrieve the service ticket from the URL that sent me back to my page. There doesn't seem to be any examples anywhere to complete steps 4 and 5 of the process. Is it correct that I need to write my own code to do that?
I have attempted to get the ticket back and then send it off to the validation service using some of my own code with cURL or fsockopen with no luck.
if (isset($_GET['ticket']))
{
$currentProtocol = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') ? 'https://' : 'http://';
$requestUri = explode('?', $_SERVER['REQUEST_URI']);
$requestUri = $requestUri[0];
$ticket = $_GET['ticket'];
$port = ($_SERVER['SERVER_PORT'] != 80) ? ':8080' : '';
$currentUrl = urlencode($currentProtocol . $_SERVER['SERVER_NAME'] . $port . $requestUri);
$validateUrl = 'ssl://server.com/cas/serviceValidate?service=' . $currentUrl . '&ticket=' . $ticket;
$errno = 0;
$errstr = '';
$fp = fsockopen($validateUrl, 443, $errno, $errstr, 30);
if (!$fp) {
echo "$errstr ($errno)<br />\n";
}
else {
var_dump($fp);
$out = "GET / HTTP/1.1\r\n";
$out .= "Host: www.example.com\r\n";
$out .= "Connection: Close\r\n\r\n";
fwrite($fp, $out);
while (!feof($fp)) {
echo fgets($fp, 128);
}
fclose($fp);
}
}
I can get a legitimate response from the service if I access it through the browser directly e.g:
https://server.com/cas/serviceValidate?service=http%3A%2F%2Flocalhost%3A8080%2Ftestcas%2Fcas-client.php&ticket=ST-35717-XLiWQ2ucCCuks2wsVNMJ-cas
Which returns an XML response containing the Active Directory User ID:
<cas:serviceResponse xmlns:cas='http://www.server.com/cas'>
<cas:authenticationSuccess>
<cas:user>c314317</cas:user>
</cas:authenticationSuccess>
</cas:serviceResponse>
But I really think I need to be able to access that URL directly from the server side with PHP, then once I have the user ID I can link that back with our systems and log them into the site.
My problem is there doesn't seem to be any code to handle the ticket and validation side of things. Can anyone point me in the right direction?
Thanks very much.
OK I think I solved the problem with cURL. I didn't have the CURLOPT_SSL_VERIFYPEER set to false and that's why it was failing. I can now get the XML response with PHP, process the XML response and retrieve the user ID. Here's the code:
// Get the current server address we are executing the PHP from
$currentProtocol = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') ? 'https://' : 'http://';
$requestUri = explode('?', $_SERVER['REQUEST_URI']);
$requestUri = $requestUri[0];
$ticket = $_GET['ticket'];
$port = ($_SERVER['SERVER_PORT'] != 80) ? ':' . $_SERVER['SERVER_PORT'] : ''; # Don't need the port if it's 80, but needed if for example test server is running port 8080
$currentUrl = $currentProtocol . $_SERVER['SERVER_NAME'] . $port . $requestUri;
// Setup the validation URL
$validateUrl = 'https://sso.server.com/cas/serviceValidate?service=' . strtolower(urlencode($currentUrl)) . '&ticket=' . $ticket;
// Send request to validate the URL
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $validateUrl); # The URL to get the data from
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); # Return the value of curl_exec() instead of outputting it out directly.
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 120); # The number of seconds to wait while trying to connect
curl_setopt($ch, CURLOPT_TIMEOUT, 120); # The maximum number of seconds to allow cURL functions to execute
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); # Check the existence of a common name and also verify that it matches the hostname provided
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); # Stop cURL from verifying the peer's certificate
curl_setopt($ch, CURLOPT_HEADER, false); # Don't include the header in the output
// Execute the request and close the handle
$xml = curl_exec($ch);
curl_close($ch);
// Get the user ID from the XML using XPath
$xml = new SimpleXMLElement($xml);
$result = $xml->xpath('cas:authenticationSuccess/cas:user');
$userId = null;
while(list( , $node) = each($result))
{
$userId = (string) $node;
}
echo 'user: ' . $userId . "<br>";
I'm trying to get the real file URL from a url that doesn't show up the real file name.
My url is like this http://video.premium.com/file/ee7bfec921cfbe16e6f08e282992b99670a00ca3/3
If I could get the real file url I could stream it directly online through a web player, but it needs .mp4 or other file format to play, just the url http://video.premium.com/file/ee7bfec921cfbe16e6f08e282992b99670a00ca3/3 doesnt work.
but when I open the URL using VLC media player, it works. doesn't work with online flash or other players..
Is this even possible? Anyway to do this?
With curl, use this: It follows the redirect until it finds the endpoint. In the included code I used goo.gl to shorten the url to a rando image. You will see the output is the original link (and it would output whatever number of redirects and their URLs), and the final redirect to the actual file. I think this is what you are looking for. I did not write this originally, but found it somewhere some time ago and reused it many times again with tweaking when needed. It seems to fit well in many places. Glad to pass it on. I think it might help to achieve what you are looking for.
<?php
function follow_redirect($url){
$redirect_url = null;
if(function_exists("curl_init")){
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_NOBODY, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
}
else{
$url_parts = parse_url($url);
$sock = fsockopen($url_parts['host'], (isset($url_parts['port']) ? (int)$url_parts['port'] : 80));
$request = "HEAD " . $url_parts['path'] . (isset($url_parts['query']) ? '?'.$url_parts['query'] : '') . " HTTP/1.1\r\n";
$request .= 'Host: ' . $url_parts['host'] . "\r\n";
$request .= "Connection: Close\r\n\r\n";
fwrite($sock, $request);
$response = fread($sock, 2048);
fclose($sock);
}
$header = "Location: ";
$pos = strpos($response, $header);
if($pos === false){
return false;
}
else{
$pos += strlen($header);
$redirect_url = substr($response, $pos, strpos($response, "\r\n", $pos)-$pos);
return $redirect_url;
}
}
$url = 'http://goo.gl/66VJB';
echo '<ol>';
while(($newurl = follow_redirect($url)) !== false){
echo '<li>', $url, '</li>';
$url = $newurl;
}
echo '</ol>';
echo '', $url, '';
?>
Output:
http://goo.gl/66VJB
http://1.bp.blogspot.com/_XE0TDW07Noo/TOSVQXZtgAI/AAAAAAAAELo/aG80jZ7u_fo/s1600/aptitude_test.gif
I am trying to create a mysql user and assign it to the created database.
I have tried setting $db_host as IP address, FQD, localhost (since I am running from the same server) etc. All of these has no success.
Any advice on what I'm doing wrong? (xmlapi.php is being incuded fine)
include("xmlapi.php");
$db_host = "usingfullyqualifieddomain";
$cpuser = "myuser";
$cppass = "mypass";
$xmlapi = new xmlapi($db_host);
$xmlapi->set_port(2083);
$xmlapi->password_auth($cpuser,$cppass);
$xmlapi->set_debug(1);
//create database
print $xmlapi->api1_query($cpuser, "Mysql", "adddb", 'myDatabaseName');
//create user
print $xmlapi->api1_query($cpuser, "Mysql", "adduser", array('user' => 'myDBUser','pass'=>'myDBPwd'));
The error is probably related to the way you're making your first service call, to create the database. Here is how I do it, on CPanel 11:
$auth_user = 'XXXXXX';
$auth_pass = 'XXXXX';
$server = 'XXXXXXXX.com';
$json_client = new \xmlapi($server);
$json_client->set_output('json');
$json_client->set_port(2083);
$json_client->password_auth($auth_user, $auth_pass);
$json_client->set_debug(1);
# Create Database
$result = $json_client->api1_query( $auth_user, 'Mysql', 'adddb', array($shop->alias));
var_dump($result);
Note that the fourth parameter should be an array with the parameters, and not a string as you are doing it.
Also notice that the print on the api call result is not very useful for debugging. Try var_dump'ing it, as it will show you some more interesting information to work on.
currently, cpanel support the cpanel json api..
here you can use this code ..
this worked for me well
<?php
$cpanelusername = "cpanelusername";
$cpanelpassword = "cpanelpassword";
$domain = 'mydomain.com';
$query = "https://$domain:2083/json-api/cpanel?cpanel_jsonapi_module=Mysql&cpanel_jsonapi_func=adddb&cpanel_jsonapi_apiversion=1&arg-0=DBNAME";
$curl = curl_init(); // Create Curl Object
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER,0); // Allow self-signed certs
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST,0); // Allow certs that do not match the hostname
curl_setopt($curl, CURLOPT_HEADER,0); // Do not include header in output
curl_setopt($curl, CURLOPT_RETURNTRANSFER,1); // Return contents of transfer on curl_exec
$header[0] = "Authorization: Basic " . base64_encode($cpanelusername.":".$cpanelpassword) . "\n\r";
curl_setopt($curl, CURLOPT_HTTPHEADER, $header); // set the username and password
curl_setopt($curl, CURLOPT_URL, $query); // execute the query
$result = curl_exec($curl);
if ($result == false) {
error_log("curl_exec threw error \"" . curl_error($curl) . "\" for $query");
// log error if curl exec fails
}
curl_close($curl);
print $result;
?>
hello im trying to create a simple script which will create an account with my dedicated server using WHM
here is the simple code
<?php
// your WHM username
$whm_user = 'root';
// your WHM password
$whm_pass = 'pass';
// your WHM hostname
$whm_host = '10.10.10.10';
// new account domain or subdomain name
$user_domain = 'example.com';
// new account username (8 characters or less)
$user_name = 'example';
// new account password
$user_pass = 'example1245';
// new account contact email
$user_email = 'user#example.net';
// new account plan (must be an existing WHM plan)
$user_plan = 'Gold';
// create the account
$site = "https://{$whm_user}:{$whm_pass}#{$whm_host}:2087/scripts/wwwacct";
$params = "?plan={$user_plan}";
$params .= "&domain={$user_domain}";
$params .= "&username={$user_name}";
$params .= "&password={$user_pass}";
$params .= "&contactemail={$user_email}";
$url = $site.$params;
file_get_contents($url);
?>
this return an error
[function.file-get-contents]: failed to open stream: No error in C:\AppServ\www\cp\create-whm-account.php on line 35
then i tried to use CURL
<?php
// your WHM username
$whm_user = 'root';
// your WHM password
$whm_pass = 'pass';
// your WHM hostname
$whm_host = '10.10.10.10';
// new account domain or subdomain name
$user_domain = 'example.com';
// new account username (8 characters or less)
$user_name = 'example';
// new account password
$user_pass = 'example1245';
// new account contact email
$user_email = 'user#example.net';
// new account plan (must be an existing WHM plan)
$user_plan = 'Gold';
// create the account
$site = "https://{$whm_user}:{$whm_pass}#{$whm_host}:2087/scripts/wwwacct";
$params = "?plan={$user_plan}";
$params .= "&domain={$user_domain}";
$params .= "&username={$user_name}";
$params .= "&password={$user_pass}";
$params .= "&contactemail={$user_email}";
$url = $site.$params;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$data = curl_exec($ch);
curl_close($ch);
?>
it doesn't return any error and doesn't work neither
i don't need to return any output as this will work within another functions so i don't need to show any result just create the account within the background
I noticed that you are requesting a HTTPS URL. Extra CURL flags might be required. Very likely:
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
See also: PHP: Curl to fetch html page from HTTPS