1
所以,我一直在嘗試使用我已經建立的腳本來執行Cron :: add_line函數,但它仍然無法正常工作。腳本登錄到cPanel,但在第二部分它不執行json-api來執行函數add_line,我已經做了很多關於這個的搜索,但從來沒有找到任何讓我理解它如何在cURL中工作的東西。如何使用cURL在cPanel中執行函數?
如果我在瀏覽器中鍵入命令url,它會起作用並創建cron,否則使用我的腳本不起作用。
如果有人能幫助我感激!
謝謝!
代碼:
<?php
$username = $_REQUEST['username'];
$password = $_REQUEST['password'];
$site = 'https://' . $_REQUEST['site'] . ':2083';
$auth_url = $site . '/login/?';
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_URL, $auth_url);
curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookies.txt');
curl_setopt($ch, CURLOPT_POSTFIELDS, 'user=' . $username . '&pass=' . $password);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 100020);
$result = curl_exec($ch);
$h = curl_getinfo($ch);
if ($result == true && strpos($h['url'], "cpsess"))
{
$pattern = "/.*?(\/cpsess.*?)\/.*?/is";
$preg_res = preg_match($pattern, $h['url'], $cpsess);
}
$cpcmd_url = $site . "$ENV{'" . $cpsess[1] . "'}" . '/json-api/';
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_URL, $cpcmd_url);
curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookies.txt');
curl_setopt($ch, CURLOPT_POSTFIELDS, 'cpanel?user=$username&cpanel_jsonapi_module=Cron&cpanel_jsonapi_func=add_line&cpanel_jsonapi_version=2&command=GET http://www.cdihost.com.br/admin/cron.php&day=*&hour=*&minute=*/5&month=*&weekday=*');
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 100020);
$result = curl_exec($ch);
curl_close($ch);
?>
謝謝!我這樣做,發現錯誤!現在,它完美無缺! :) –