0

您好,我正在尝试创建一个简单的脚本,该脚本将使用 WHM 在我的专用服务器上创建一个帐户,这是简单的代码

<?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);
?>

这返回一个错误

[function.file-get-contents]: failed to open stream: No error in C:\AppServ\www\cp\create-whm-account.php on line 35

然后我尝试使用 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); 
?>

它不返回任何错误,也不工作我不需要返回任何输出,因为这将在另一个函数中工作,所以我不需要显示任何结果,只需在后台创建帐户

4

1 回答 1

0

我注意到您正在请求一个 HTTPS URL。可能需要额外的 CURL 标志。很可能:

curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,  2); 

另请参阅:PHP:Curl 从 HTTPS 获取 html 页面

于 2011-08-03T18:53:09.173 回答