Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
1.5 kB
1
Indexable
Never
<?php

$apiKey = 'fd4T6JraS0ME1yv+RaVJ8CP0bKFckLucoZ8rkgMCNHo='; // API anahtarınızı buraya girin
$cronId = $_POST['cron_id']; // Posttan gelen cron_id değerini alın
$newUrl = $_POST['cron_ad']; // Posttan gelen yeni URL değerini alın
 
    if (isset($_POST['cron_durum'])) {
        $cron_durum = $_POST['cron_durum'];
        $job_enabled = $cron_durum === 'true' ? 'true' : 'false';
        echo $job_enabled;
    }


$url = 'https://api.cron-job.org/jobs/'.$cronId;

$data = array(
    'job' => array(
        'url' => $newUrl,
         'enabled' => $job_enabled
    )
);

$headers = array(
    'Content-Type: application/json',
    'Authorization: Bearer ' . $apiKey
);

$ch = curl_init($url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PATCH');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
$response = curl_exec($ch);

if ($response === false) {
    echo 'Curl hatası: ' . curl_error($ch);
} else {
    $responseData = json_decode($response, true);

    if (isset($responseData['jobId'])) {
        echo 'Cron Görevi ID: ' . $responseData['jobId'] . '<br>';
        echo 'Cron Görevi URL: ' . $responseData['url'] . '<br>';
         $job_enabled = $cron_durum === 'true' ? 'true' : 'false';
    } elseif (isset($responseData['error'])) {
        echo 'API Hatası: ' . $responseData['error'];
    } else {

    }
}

curl_close($ch);

?>