我正在编写一个脚本来向主机控制面板“VESTA”添加一个新用户。我根据api手册编写:http: //vestacp.com/docs/api/执行代码时不会产生错误,但用户未添加到VESTA。我的代码:
$vst_hostname = 'dfsdfl.csfdsdsgds.com';
$postvars = array(
$vst_username = 'zdeslogin',
$vst_password = 'zdesparol',
$vst_returncode = 'yes',
$vst_command = 'v-add-user',
$username = 'demo',
$password = 'password',
$email = 'demo@gmail.com',
$package = 'default',
$fist_name = 'Rust',
$last_name = 'Cohle'
);
$postdata = http_build_query($postvars);
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, 'https://' . $vst_hostname . ':8083/api/');
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata);
$answer = curl_exec($curl);
// Check result
if($answer == 0) {
echo "User account has been successfuly created\n";
} else {
echo "Query returned error code: " .$answer. "\n";
}
运行代码后,返回以下行: User account has been successfully created.