title: How can I execute functions in cPanel using cURL?
body: <p>So, I've been trying to execute the function Cron::add_line using an script that I have builded and it didn't work properly yet. The script login into cPanel but in the second part it don't execute the json-api to execute the function add_line, I've did many searches about this but never found anything to make me comprehend how it works in cURL.</p>
  
  <p>If I type the command url in my browser, it works and create the cron, otherwise, using my script it doesn't work.</p>
  
  <p>If anyone could help I appreciate!</p>
  
  <p>Thanks!</p>
  
  <p>Code:</p>
  
  <pre><code>&lt;?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 . '&amp;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 &amp;&amp; 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&amp;cpanel_jsonapi_module=Cron&amp;cpanel_jsonapi_func=add_line&amp;cpanel_jsonapi_version=2&amp;command=GET http://www.cdihost.com.br/admin/cron.php&amp;day=*&amp;hour=*&amp;minute=*/5&amp;month=*&amp;weekday=*');
  curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
  curl_setopt($ch, CURLOPT_TIMEOUT, 100020);
  $result = curl_exec($ch);
  curl_close($ch);
  ?&gt;
  </code></pre>